so my arduino is hooked up to a pontimeter 10k on a0 and when i have it at values 256, 512, 769 the led connected to 9 restarts to 0 and acts like it started off like the pontimeter is 0, that is the same with any port any any other power draining device but here is my code
int red;
void setup(){
int red = 0;
Serial.begin(9600);
}
void loop(){
red = analogRead(A0);
Serial.print(red);
analogWrite(9, red);
Serial.print(analogRead(A1));
delay(50);
}
just before this started happening the device just awkwardly restarted and had to be plugged in again to communicate.
Yes it will.
Analog read returns a 10 bit value that is between 0 and 1023.
Where as analog write takes in an 8 bit value, that is from 0 to 255.
So when you give the analog write 256 it wraps round and in effect gives zero.
To stop this from happening use:-
Grumpy_Mike:
Yes it will.
Analog read returns a 10 bit value that is between 0 and 1023.
Where as analog write takes in an 8 bit value, that is from 0 to 255.
So when you give the analog write 256 it wraps round and in effect gives zero.
To stop this from happening use:-
red = analogRead(A0) >> 2;
Which basically divides the reading by four.
Moderator edit: Hmmm.
well this device was not working like divide by four it would equal the exact same as the pont, worked fine before the device glitched out, but what I want to know is how to actually get 1024 out of the led. not 255.
but what I want to know is how to actually get 1024 out of the led. not 255.
I recognise the words but I can attach no meaning to them.
You do not get anything out of an LED 1024 or 255!
You feed an LED with a voltage that lights it up, and the resistor keeps the current in check.
The analogue output is just PWM it is not an output of changing voltage.
See:- http://www.thebox.myzen.co.uk/Tutorial/PWM.html