mirror of
https://github.com/esp8266/Arduino.git
synced 2025-06-25 06:22:11 +03:00
Added new switch case example
This commit is contained in:
45
build/shared/dist/examples/Control/switchCase/applet/switchCase.cpp
vendored
Normal file
45
build/shared/dist/examples/Control/switchCase/applet/switchCase.cpp
vendored
Normal file
@ -0,0 +1,45 @@
|
||||
|
||||
#include "WProgram.h"
|
||||
void setup();
|
||||
void loop();
|
||||
void setup() {
|
||||
Serial.begin(9600);
|
||||
}
|
||||
void loop() {
|
||||
int distance = analogRead(0);
|
||||
|
||||
int range = map(distance, 0, 600, 0, 3);
|
||||
|
||||
switch (range) {
|
||||
case 0:
|
||||
Serial.println("dark");
|
||||
break;
|
||||
case 1:
|
||||
Serial.println("dim");
|
||||
break;
|
||||
case 2:
|
||||
Serial.println("medium");
|
||||
break;
|
||||
case 3:
|
||||
Serial.println("bright");
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
int main(void)
|
||||
{
|
||||
init();
|
||||
|
||||
setup();
|
||||
|
||||
for (;;)
|
||||
loop();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
Reference in New Issue
Block a user