I an trying to write a program to reverse three leds counting up in binary when a button is pressed the count is reverse and counts down. The program i have wrote will work to count up but will not reverse when the button is pressed. If any one could help me i would be very grateful thank you for your time.....here is my program
int button =7; // switch is connected to pin 7
int led1Pin = 11;
int led2pin = 12;
int led3pin = 13;
void setup()
{
pinMode(13, OUTPUT);
pinMode(12, OUTPUT);
pinMode(11, OUTPUT);
pinMode(7, INPUT);
}
int count=0;
int change=1;
void loop() {
digitalWrite(13, bitRead(count,2));
digitalWrite(12, bitRead(count,1));
digitalWrite(11, bitRead(count,0));
delay(1000);
count=count+change;
val=digitalRead(7);
if(val) {
change=change;
}
}
You asked the same question, on the same part of the forum, 14 hours ago, and I answered then. Ok, I didn't give a solution like G_M did, but I did point out the problem.
You asked the same question, on the same part of the forum, 14 hours ago
@treky2013 you are a very naughty boy, don't do it again, that is the way to get banned.
a solution like G_M did,
Yes well it is Christmas.
but I did point out the problem.
Lets see if he can work out what I have put then.
I am expecting a post saying it will not work because there is an error message saying that incrementValue was not declared in this scope.
Wow seconds after writing that I got a PM saying:-
Thanks grump mac for your help i have just tried to incorporate you recommendation and i am getting an error in the verify as you can tell i am quite new at arduinos could you have a look at it for me again plz. thanks for your help
Read how to use this forum sticky.
Do not use PMs for asking technical questions.
Read your code and try and follow what it is doing. It is apparent you are learning nothing from the help you are being given. If I give you the complete code then you will learn nothing at all will you.
Hint read about variables and what they do and how to declare them.
Plus Mike I'm not sure your logic is 100s.... I think it needs to change the sign of change from what it is at a moment, not make it explicitly +1 or -1, probably rather a times by -1
I think it needs to change the sign of change from what it is at a moment,
No he needs to increment or decrement, you could do this by multiplying by -1 but that is not a good method because things could get out of sync and thus the button would act in the reverse direction. Better to explicitly set the increment value.
But I think it needs to change direction on the button push, which ever way it was going, and the way I understand yours it sets it to 1 on press, -1 otherwise.
But lets wait till the OP gives it a whirl, so to speak.