wsme
Member
Hey all,
Very new to circuit design. Just learned analogRead() for analog input. Wanted to make a toggle switch, so I used the following code:
This works when OUTPIN is one of the PWM ports listed on the pinout reference page (12, 14, 15).
Below is the circuit used for a working design from 2 angles:
http://https://imgur.com/a/rYl72Ug
Why does the circuit only work when power is given to the pwm pins?
Very new to circuit design. Just learned analogRead() for analog input. Wanted to make a toggle switch, so I used the following code:
Code:
// Toggle button
#define OUTPIN 12 //<- THIS MACRO
void setup() {
Serial.begin(38400);
pinMode(OUTPIN, OUTPUT);
}
int input;
int state = 0;
void loop() {
input = analogRead(10);
if (input > 400 && !(state)) {
analogWrite(OUTPIN, 1);
// Serial.print("Success\n");
state = 1;
} else if (analogRead(10) > 400 && state) {
// Serial.print("Success2\n");
analogWrite(OUTPIN, 0);
state = 0;
}
delay(100);
}
This works when OUTPIN is one of the PWM ports listed on the pinout reference page (12, 14, 15).
Below is the circuit used for a working design from 2 angles:
http://https://imgur.com/a/rYl72Ug
Why does the circuit only work when power is given to the pwm pins?