Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int updateBulb(String command);
- int updateRGB(String command);
- void setup() {
- Serial1.begin(9600);
- pinMode(D7, OUTPUT);
- digitalWrite(D7, LOW);
- // register the Spark functions
- Spark.function("updateBulb", updateBulb);
- Spark.function("updateRGB", updateRGB);
- RGB.control(true);
- RGB.color(0, 0, 0);
- }
- void loop() {
- // Nothing needs to be looped
- }
- int updateBulb(String command){
- String cmdF = command.substring(0);
- int rNum = cmdF.toInt();
- if (rNum == 1) {
- digitalWrite(D7,HIGH);
- return 1;
- }
- if (rNum == 0) {
- digitalWrite(D7,LOW);
- return 2;
- }
- return 0;
- }
- int updateRGB(String command){
- String cString = command.substring(0);
- int cNum = cString.toInt();
- if(cNum == 1){
- Serial1.print("1"); //decrease RED
- return 11;
- }
- if(cNum == 2){
- Serial1.print("2"); //increase RED
- return 12;
- }
- if(cNum == 3){
- Serial1.print("3"); //decrease GREEN
- return 13;
- }
- if(cNum == 4){
- Serial1.print("4"); //increase GREEN
- return 14;
- }
- if(cNum == 5){
- Serial1.print("5"); //decrease BLUE
- return 15;
- }
- if(cNum == 6){
- Serial1.print("6"); //increase BLUE
- return 16;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement