i_makes_stuff

Spark Core code - Minecraft Christmas Tree

Feb 10th, 2015
877
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. int updateBulb(String command);
  2.  
  3. int updateRGB(String command);
  4.  
  5. void setup() {
  6.    
  7.     Serial1.begin(9600);
  8.    
  9.     pinMode(D7, OUTPUT);
  10.     digitalWrite(D7, LOW);
  11.    
  12.     // register the Spark functions
  13.     Spark.function("updateBulb", updateBulb);
  14.     Spark.function("updateRGB", updateRGB);
  15.    
  16.     RGB.control(true);
  17.     RGB.color(0, 0, 0);
  18.  
  19. }
  20.  
  21.  
  22. void loop() {
  23.                  // Nothing needs to be looped
  24.     }
  25.    
  26.    
  27. int updateBulb(String command){
  28.  
  29.     String cmdF = command.substring(0);
  30.  
  31.     int rNum = cmdF.toInt();
  32.  
  33.     if (rNum == 1) {
  34.         digitalWrite(D7,HIGH);
  35.         return 1;
  36.         }
  37.    
  38.     if (rNum == 0) {
  39.         digitalWrite(D7,LOW);
  40.         return 2;
  41.         }
  42.        
  43.     return 0;
  44.    
  45.     }
  46.    
  47.    
  48. int updateRGB(String command){
  49.    
  50.     String cString = command.substring(0);
  51.     int cNum = cString.toInt();
  52.    
  53.     if(cNum == 1){
  54.         Serial1.print("1"); //decrease RED
  55.         return 11;
  56.         }
  57.     if(cNum == 2){
  58.         Serial1.print("2"); //increase RED
  59.         return 12;
  60.         }
  61.     if(cNum == 3){
  62.         Serial1.print("3"); //decrease GREEN
  63.         return 13;
  64.         }
  65.     if(cNum == 4){
  66.         Serial1.print("4"); //increase GREEN
  67.         return 14;
  68.         }
  69.     if(cNum == 5){
  70.         Serial1.print("5"); //decrease BLUE
  71.         return 15;
  72.         }
  73.     if(cNum == 6){
  74.         Serial1.print("6"); //increase BLUE
  75.         return 16;
  76.         }
  77.     return 0;
  78. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×