Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Forked codes:
- Adafruit Arduino - Lesson 3. RGB LED by Simon Monk
- Internet connected LED - Week 3 lecture
- Edited by: Christian Veloso
- Weather Cloud
- */
- // Define the RGB LED pins we're going to use
- int redPin = A0;
- int greenPin = A1;
- int bluePin = A2;
- //uncomment this line if using a Common Anode LED
- //#define COMMON_ANODE
- // This routine runs only once upon reset
- void setup()
- {
- //Register a Spark function. We will call this function to control the RGB LED
- Spark.function("condition", weatherCondition);
- //initialize the LED pin as an output.
- pinMode(redPin, OUTPUT);
- pinMode(greenPin, OUTPUT);
- pinMode(bluePin, OUTPUT);
- // set the LED to be OFF
- analogWrite(redPin, LOW);
- analogWrite(greenPin, LOW);
- analogWrite(bluePin, LOW);
- }
- void loop()
- {
- // Nothing to do here
- }
- // This function gets called whenever there is a matching API request
- int weatherCondition(String command)
- {
- //find out the pin number and convert the ascii to integer
- int pinNumber = command.charAt(0) - '0';
- switch (pinNumber)
- {
- //If weather condition is sunny
- case 1:
- setColor(255, 191, 0); // sunburst orange
- break;
- //If weather condition is cloudy
- case 2:
- setColor(255, 255, 255); // white
- break;
- //If weather condition is raining
- case 3:
- setColor(8, 8, 138); // dark blue
- break;
- }
- }
- //Adafruit Arduino - Lesson 3. RGB LED by Simon Monk
- void setColor(int red, int green, int blue)
- {
- #ifdef COMMON_ANODE
- red = 255 - red;
- green = 255 - green;
- blue = 255 - blue;
- #endif
- analogWrite(redPin, red);
- analogWrite(greenPin, green);
- analogWrite(bluePin, blue);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement