top of page

BUTTON PRESS reference and our OWN work 1

For interaction between people and box, we referenced several different codes of developers to support a reliable logic and system.


First below is the "Button" control codes sample we used for as a reference to run a "Press" driven interaction.


The Reference:

From Yi Hong

int Button=3; int LED=13; boolean onoff=LOW; void setup() { pinMode(Button,INPUT); pinMode(LED,OUTPUT); } void loop(){ if(digitalRead(Button)==LOW) { delay(10); if(digitalRead(Button)==HIGH) { digitalWrite(LED,onoff); onoff=(!onoff);

delay(10); while(digitalRead(Button)==HIGH) { delay(1); } } } }




Our OWN Type below, do logical change on logic. As we have a full loop selector, so we change the part of checking the state of Button to IF & ELSE instead of IF include IF. But we do learn how to clear the noise and wrong switching on, by a 1K resistor for a more stable switch.


if (digitalRead(Button)==LOW) { delay(10); max7219.show(maxBitmap[0]); Serial.print(" Statue - "); Serial.println("ALL OFF"); if (mp3.available()) { printDetail(mp3.readType(), mp3.read()); //Print the detail message from DFPlayer to handle different errors and states. } } else if (digitalRead(Button)==HIGH) { delay(10); if ( ds18b20.getTempC() >= 32 ) { //temperatureDetect-R digitalWrite(greenLED, LOW); digitalWrite(yellowLED, LOW); digitalWrite(redLED, HIGH); Serial.print(" Statue - "); Serial.println("WARM"); Serial.print(" redLED - "); Serial.println("ON"); for (int index = 0; index < 1; index++) { //music play mp3.play(2); if (mp3.available()) { printDetail(mp3.readType(), mp3.read()); //Print the detail message from DFPlayer to handle different errors and states. } } for (int index = 0; index < 1; index++) { //led animation delay(500); max7219.show(maxBitmap[6]); delay(2000); max7219.show(maxBitmap[7]); delay(1000); } delay(100); digitalWrite(greenLED, LOW); digitalWrite(yellowLED, LOW); digitalWrite(redLED, LOW); Serial.print(" redLED - "); Serial.println("OFF"); max7219.show(maxBitmap[0]); mp3.pause(); if (mp3.available()) { printDetail(mp3.readType(), mp3.read()); //Print the detail message from DFPlayer to handle different errors and states. } while (!(32>ds18b20.getTempC())) {} }//redLED

Commenti


bottom of page