Instead of trying yo explain everything it will be able to show you my code and then tell you the problem...
int ADC0 = 0;
int value;
int newValue;
int LEDpin = 13;
void setup() {
Serial.begin(9600);
pinMode(LEDpin, 1);
value = analogRead(ADC0);
}
void loop() {
newValue = analogRead(ADC0);
if(value == newValue){
digitalWrite(LEDpin, 1);
}else{
digitalWrite(LEDpin, 0);
value = newValue;
Serial.print("Time: ");
String valueS = String(value);
String timer = String(valueS + "0ms");
Serial.println(timer);
}
delay(1000);
}
This is the code I have i want to output the the value only when the value has been changed the problem I'm having is getting a starting value that does not reset every second when the loops resets it also resets the value so its not got a value to compare against to see weather it has changed.
Hi Ray,
I have a 10k pot attached to pin A01.....
Thankyou for the suggestion i have tried it and it does not seem to work still. I have commented all the rest of the loop out and just printed the value and i am getting a value of 0.
int ADC0 = 0;
int value = analogRead(ADC0);
int newValue;
int LEDpin = 13;
void setup() {
Serial.begin(9600);
pinMode(LEDpin, 1);
}
void loop() {
Serial.println(value);
delay(1000);
}
Everything is wired up correctly, I can get a reading from the pot. I followed a tutorial from a book for the first part i am now just trying to practise and build up my skills in both the programing side and the electronic sides. What i am trying to achieve from this is for the pot to read back a reading which I have outputted as a time, then I am planning on adding a button and using the time variable set from the pot to set a timer and once that has timed out for a buzzer to go off. I hope this helps understand what I am doing.
And I think I confused you with my extract from your code. I didn't mean for you to move the analogRead() statement up front like that Move it into your cut down loop() code before you print the value.
First, your code would be a lot less confusing if you used names like currValue for the current value and prevValue for the previous value.
Second, it makes no sense to compare value and newValue when you have not assigned values to either one. The FIRST thing to do in loop is to assign a value to currValue (newValue). Then, compare that to prevValue (value).
Finally, the copy of currValue (newValue) to prevValue (value) should be unconditional.