Skill Dev I: A Simple Internet Appliance

Made by Kevin Chou

Goal: To get oriented with the Particle platform, build first circuit, and code first project.

Created: October 28th, 2022

0

Outcome

The Yellow, Red, and RGB LEDs can be controlled on the Particle console through functions. Yellow and Red LEDs can be toggled on and off by typing "HIGH", "HI", "LOW", and "LO". Each color pin of the RGB LED is PWM enabled, with 0 being the max brightness and 255 being off for each color. RGB LED can be controlled by typing in values for "R, G, B" in the particle console.

Video demonstration: https://cmu.box.com/s/dvxta8d160s7b5yz3d3686j4toqltkkz

0
int redPin = A5;
int greenPin = A4;
int bluePin = A3;

int redValue = 255; // Full brightness for an Cathode RGB LED is 0, and off 255
int greenValue = 255; // Full brightness for an Cathode RGB LED is 0, and off 255
int blueValue = 255; // Full brightness for an Cathode RGB LED is 0, and off 255

int ledPin = D2;
int ledPin2 = D3;

int ledControl(String command)
{
   int state = LOW;

   // find out the state of the led
   if(command == "HIGH" || command == "HI"){
	   state = HIGH;
   }else if(command == "LOW" || command == "LO"){ 
	   state = LOW;
   }else{
	   return -1;
   }

   // write to the appropriate pin
   digitalWrite(ledPin, state);
   return 1;
}

int led2Control(String command)
{
   int state = LOW;

   // find out the state of the led
   if(command == "HIGH" || command == "HI"){
	   state = HIGH;
   }else if(command == "LOW" || command == "LO"){ 
	   state = LOW;
   }else{
	   return -1;
   }

   // write to the appropriate pin
   digitalWrite(ledPin2, state);
   return 1;
}

int RGBControl(String command){
    //0 is HI, 255 is LOW b/c CATHODE RGB LED
    String colors[3];
    colors[0]="";
    colors[1]="";
    colors[2]="";

    int index = 0;
    for( int i = 0; i < command.length(); i++ )
    {
      if( index < 3 ){
        char c = command.charAt(i);
        colors[index] += c;

        if( c == ',') index++;
      }
    }

    // get the red component...
    redValue = colors[0].toInt();
    // now green
    greenValue = colors[1].toInt();
    // now blue
    blueValue = colors[2].toInt();

   // write the mixed color
   analogWrite( redPin, redValue);
   analogWrite( greenPin, greenValue);
   analogWrite( bluePin, blueValue);

   return 1;
}

void setup() {
    // Configure the pins to be outputs
   pinMode(ledPin, OUTPUT);
   pinMode(ledPin2, OUTPUT);
   
   //Uses CATHODE RGB LED, 255 is OFF, 0 is ON
   pinMode(redPin, OUTPUT);
   pinMode(greenPin, OUTPUT);
   pinMode(bluePin, OUTPUT);
   //Start up as OFF
   analogWrite(redPin, 255);
   analogWrite(greenPin, 255);
   analogWrite(bluePin, 255);

   // Initialize both the LEDs to be OFF
   digitalWrite(ledPin, LOW);
   digitalWrite(ledPin2, LOW);
   
   //Register our Particle function here
   Particle.function("led", ledControl);
   Particle.function("led2", led2Control);
   
   //RGB
   Particle.function("RGB LED", RGBControl);
}

void loop() {
    //loop
    //particle analog read range is 0-4095
}
Click to Expand
0

Process

Followed the "A Simple Internet Appliance" and "LEDs Continued" DioT Labs tutorials.

0

Reflection

Though this lab, I learned how to connect to the Argon, how to flash over the air, and how to set up functions in the Particle console to control the IOs of the board.

0
x
Share this Project

Courses

About

Goal: To get oriented with the Particle platform, build first circuit, and code first project.