Advertisement
Guest User

Untitled

a guest
May 15th, 2015
270
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.79 KB | None | 0 0
  1. /* Forked codes:
  2. Adafruit Arduino - Lesson 3. RGB LED by Simon Monk
  3. Internet connected LED - Week 3 lecture
  4.  
  5. Edited by: Christian Veloso
  6. Weather Cloud
  7. */
  8.  
  9. // Define the RGB LED pins we're going to use
  10. int redPin = A0;
  11. int greenPin = A1;
  12. int bluePin = A2;
  13.  
  14. //uncomment this line if using a Common Anode LED
  15. //#define COMMON_ANODE
  16.  
  17. // This routine runs only once upon reset
  18. void setup()
  19. {
  20. //Register a Spark function. We will call this function to control the RGB LED
  21. Spark.function("condition", weatherCondition);
  22.  
  23. //initialize the LED pin as an output.
  24. pinMode(redPin, OUTPUT);
  25. pinMode(greenPin, OUTPUT);
  26. pinMode(bluePin, OUTPUT);
  27.  
  28. // set the LED to be OFF
  29. analogWrite(redPin, LOW);
  30. analogWrite(greenPin, LOW);
  31. analogWrite(bluePin, LOW);
  32. }
  33.  
  34. void loop()
  35. {
  36. // Nothing to do here
  37. }
  38.  
  39. // This function gets called whenever there is a matching API request
  40. int weatherCondition(String command)
  41. {
  42. //find out the pin number and convert the ascii to integer
  43. int pinNumber = command.charAt(0) - '0';
  44. switch (pinNumber)
  45. {
  46. //If weather condition is sunny
  47. case 1:
  48. setColor(255, 191, 0); // sunburst orange
  49. break;
  50.  
  51. //If weather condition is cloudy
  52. case 2:
  53. setColor(255, 255, 255); // white
  54. break;
  55.  
  56. //If weather condition is raining
  57. case 3:
  58. setColor(8, 8, 138); // dark blue
  59. break;
  60. }
  61. }
  62.  
  63. //Adafruit Arduino - Lesson 3. RGB LED by Simon Monk
  64. void setColor(int red, int green, int blue)
  65. {
  66. #ifdef COMMON_ANODE
  67. red = 255 - red;
  68. green = 255 - green;
  69. blue = 255 - blue;
  70. #endif
  71. analogWrite(redPin, red);
  72. analogWrite(greenPin, green);
  73. analogWrite(bluePin, blue);
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement