Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
const int Button_Min = 100; // Button minimum, discovered through experiment
const int Button_Max = 1023; // Button maximum, discovered through experiment
void setup() {
// initialize serial communication:
Serial.begin(9600);
}
void loop() {
// read the Button
int Buttons_read = analogRead(A0);
// map the Button range to a range of five options:
int Button = map(Buttons_read, Button_Min, Button_Max, 0, 4);
// do something different depending on the
// Button value:
switch (Button) {
case 0: // your hand is on the Button
Serial.println("button1");
break;
case 1: // your hand is close to the Button
Serial.println("button2");
break;
case 2: // your hand is a few inches from the Button
Serial.println("button3");
break;
case 3: // your hand is nowhere near the Button
Serial.println("button4");
break;
case 4: // your hand is nowhere near the Button
Serial.println("button5");
break;
}
}