Hello, i ran into a problem trying to make a simple switch system of no particular purpose.
int startswitch = 0;
int setswitch = 1;
int startval;
int setval;
void setup() {
Serial.begin(9600);
Serial.println("Super Serial Work Initiated");
pinMode(startswitch, INPUT);
pinMode(setswitch, INPUT);
}
void loop() {
setval = digitalRead(setswitch);
startval = digitalRead(startswitch);
if (setval != 0) {
Serial.println("set");
}
else{
Serial.println("B");
}
if (startval != 0) {
Serial.println("Start");
}
else{
Serial.println("A");
}
}
Basically, i hooked up 2 switches to my arduino and tried to program it so that the Serial Monitor prints something in indication of button detected.
however, it only detects whatever switch is on pin 0, and returns a corrupted ACII character when switch corresponding to pin 1 is pressed (even when the if/else statements for the switch is disabled)
i checked online to make sure my hardware wasn't flawed (wire from pin to switch to gnd), and everybody i have consulted so far don't see any problems in the code. there are no error messages when uploading, either.
Looking good
You might add a few comments, for example the title and date at the top.
Do you know the auto-text-layout-format (Ctrl+T) ? It is in the 'Tools' menu. That will rearrange the indents and so, to make it look better. Also when a '}' is missing, the Ctrl+T will show almost immediate where it did go wrong.