Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define SENSOR A0
- #define LED 5
- int val;
- unsigned int value = 0;
- void setup() {
- pinMode(LED, OUTPUT);
- pinMode(SENSOR, INPUT);
- Serial.begin(9600);
- }
- void loop() {
- value = analogRead(SENSOR);
- if (Serial.available())
- {
- val = Serial.read();
- if (val == '0'){
- Serial.println("enable command: 0");
- digitalWrite(LED, 0);
- }
- if (val == '1'){
- Serial.println("enable command: 1");
- if (value<250) {digitalWrite(LED, 255); }
- }
- if (val == '2'){
- Serial.println("enable command: 2");
- if(value < 500){ digitalWrite(LED, value%255); }
- if (val == '3'){
- Serial.println("enable command: 3");
- if(value > 250){ digitalWrite(LED, 0); }else{
- if(value < 500){ digitalWrite(LED, value%255; }
- }
- }
- }
- }
- }
- *\
- https://imgur.com/a/B3dCK6h
- \*
Add Comment
Please, Sign In to add comment