Created
August 9, 2023 19:46
-
-
Save Workshopshed/553722d1342064fe000162cc2c1832c7 to your computer and use it in GitHub Desktop.
A test to do see if we can modify the volatile variable in the middle of a switch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
volatile uint8_t position = 0; | |
uint8_t test = 0; | |
const byte outpin = 3; //Wire from 2 to 3 | |
const byte interruptPin = 2; | |
void setup() { | |
pinMode(outpin, OUTPUT); | |
pinMode(interruptPin, INPUT_PULLUP); | |
attachInterrupt(digitalPinToInterrupt(interruptPin), blink, CHANGE); | |
Serial.begin(9600); | |
while (!Serial) { | |
; // wait for serial port to connect. Needed for native USB port only | |
} | |
} | |
void blink() { | |
position = position+1; | |
} | |
void loop() { | |
position = 1; | |
test = 0; | |
switch (position) { | |
case 1: | |
test = test + 1; | |
digitalWrite(outpin, HIGH); | |
digitalWrite(outpin, LOW); | |
break; | |
case 2: | |
test = test + 2; | |
position = 9; | |
break; | |
case 9: | |
test = test + 4; | |
position = 10; | |
break; | |
case 10: | |
test = test + 8; | |
break; | |
case 20: | |
test = test + 8; | |
break; | |
case 30: | |
test = test + 8; | |
break; | |
case 50: | |
test = test + 8; | |
break; | |
case 128: | |
test = test + 8; | |
break; | |
default: | |
test = 99; | |
} | |
Serial.println(test); | |
Serial.println("Done"); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment