int SendPin = A0; //Send signal out
int ReadPin = A1; //Read the signal
int val = 0; //The value of the read
int buttonPin = D0; // Button Pin
int pageN = 0;
int status = 0;
int ButtonStatus = 0;
void setup(){
Serial.begin(9600);
pinMode(SendPin, OUTPUT);
pinMode(ReadPin, INPUT);
pinMode(buttonPin, INPUT_PULLUP); // sets pin as input
String P_Return = "0";
Particle.publish("doit2017/cookbook/pagenumber/preview", P_Return);
}
void loop(){
val = analogRead(ReadPin);
Serial.println(val);
if (val > 200 && val < 400 ){
pageN = 1;
} else if (val > 1800 && val < 2200 ) {
pageN = 2;
} else if (val > 3200 && val < 3400 ) {
pageN = 3;
} else {
pageN = 0;
}
if (pageN > 0 && status == 0){
Serial.println("Smell and Imagine!");
String S_pageN = String(pageN);
Particle.publish("doit2017/cookbook/pagenumber/preview", S_pageN);
status = 1;
delay(100);
} else if (pageN == 0 & status == 1){
Serial.println("See you next time");
String P_Return = "0";
Particle.publish("doit2017/cookbook/pagenumber/preview", P_Return);
status = 0;
if (ButtonStatus == 1){
Serial.println("See you next time");
String Return = "0";
Particle.publish("doit2017/cookbook/pagenumber/cook", Return);
ButtonStatus = 0;
}
delay(100);
}
Serial.print("status:");
Serial.println(status);
int buttonState = digitalRead( buttonPin );
Serial.println(buttonState);
if( buttonState == LOW && status == 1 ){
if (ButtonStatus == 0){
Serial.println("Let's Cook!");
String S_pageN = String(pageN);
Particle.publish("doit2017/cookbook/pagenumber/cook", S_pageN);
ButtonStatus = 1;
delay(100);
} else if (ButtonStatus == 1){
Serial.println("See you next time");
String Return = "0";
Particle.publish("doit2017/cookbook/pagenumber/cook", Return);
ButtonStatus = 0;
delay(100);
}
}
delay(100);
}
Click to Expand
Content Rating
Is this a good/useful/informative piece of content to include in the project? Have your say!
You must login before you can post a comment. .