I have a Program :
int led_pin = 6;
int pot_pin = A1;
int output;
int led_value;
int inPin = A2; // the number of the input pin
int outPin = 13; // the number of the output pin
int state = HIGH; // the current state of the output pin
int reading; // the current reading from the input pin
int previous = 0; // the previous reading from the input pin
// the follow variables are long's because the time, measured in miliseconds,
// will quickly become a bigger number than can be stored in an int.
long time = 0; // the last time the output pin was toggled
long debounce = 700; // the debounce time, increase if the output flickers
void setup() {
pinMode(led_pin, OUTPUT);
pinMode(6, OUTPUT);
pinMode(5 , OUTPUT);
Serial.begin(9600);
}
void loop() {
//Reading from potentiometer
output = analogRead(pot_pin);
//Mapping the Values between 0 to 255 because we can give output
//from 0 -255 using the analogwrite funtion
led_value = map(output, 0, 1023, 20, 255);
analogWrite(led_pin, led_value);
delay(1);
reading = analogRead(inPin);
Serial.println(reading);
if (reading > 1000 && previous < 900 && millis() - time > debounce) {
if (state == HIGH)
state = LOW;
else
state = HIGH;
time = millis();
}
if(state == HIGH){
pinMode(6, OUTPUT);
pinMode(5 , OUTPUT);
analogWrite(6, led_value);
digitalWrite(5,LOW);
}else{
pinMode(6, OUTPUT);
pinMode(5 , OUTPUT);
digitalWrite(6,LOW);
analogWrite(5, led_value);
}
previous = reading;
}
i have an poti connected to port A1
and a Button connected to port A2
the problem is, that i don't understand is, that the serial output is from both, the poti and the button?!
what did I do wrong?
I'm using an Arduino UNO, and I have an Motor connected to port 5 and 6
the program is also messing with the speed of the motor
the idea is, that I have an button to switch the motors direction, and the poti to regulate the speed
Please help me!!!