Back to Parent

//#include <SoftwareSerial.h>
//#include <Wire.h>

#define REDPIN D0
#define GREENPIN D1
#define BLUEPIN D2

#define FADESPEED 5     // make this higher to slow down

//SoftwareSerial ser(0,1);

int v;
String inputString="";
boolean stringComplete = false;
int r = 0;
int g = 0;
int b = 0;
int s = 0;

void setup() {
 pinMode(REDPIN, OUTPUT);
 pinMode(GREENPIN, OUTPUT);
 pinMode(BLUEPIN, OUTPUT);

 Serial.begin(9600);
 inputString.reserve(200);
 serialEvent();


// Keep a cloud variable for the current position
Particle.variable(  "spend" , v);
Particle.variable( "save", s);
Particle.variable("buget", (int)(v/0.75));

}


void loop() {
 analogWrite(REDPIN, 1200);
 analogWrite(BLUEPIN, 1200);
  if (stringComplete) {
   Serial.println(inputString);
 v = inputString.toInt();
 Serial.println(v);
 s = (int)(v * 0.33);
 analogWrite(GREENPIN, v);
  inputString = "";
  stringComplete = false;
  }


}




void serialEvent(){
  while (Serial.available()) {
 // get the new byte:
   char inChar = (char)Serial.read();
   //Serial.println(inChar);
   inputString += inChar;
   // if the incoming character is a newline, set a flag
   // so the main loop can do something about it:
   if (inChar == '\n') {
     stringComplete = true;
    }
 }
}
Click to Expand

Content Rating

Is this a good/useful/informative piece of content to include in the project? Have your say!

0