Go Down

Topic: Problem with analog read and write (Read 589 times) previous topic - next topic


So, this is my second project with arduino. I'm trying to make something similar to a clap hand games, but with 8 analog sensors, 2 in the palm of my hand, 2 on the back of my hand,  2 in my friend's palm hand,2  on the back of my hand.I'm using 2 processors, one for write(with me) and one for read(with my friend),each sensor will be represented by one color,for example, the red on my hand, need to touch with the red on his hand, and if we touch different colours, my buzzer will play a specific song alerting the mistake. 
But i am having some troubling with the analog reading value, i am testing this programs here:  obs i am using lilypad
const int red = A4;

void setup() { pinMode(vermelho,OUTPUT); }

void loop () { analogWrite(vermelho, 20); }

const int red = A4;
int val = 20;

void setup() {
Serial.begin(9600); }

void loop () {
Serial.println(analogRead(val)); }

I want my write code to pass the value 20 and my read command to read 20 for red color, but my read value is 0 if the write value is under 127, and if its higher then 127 the read value is 1023, i wish somebody could help me, i need to define 4 colours(red,blue,green and yellow) with 4 differents value for write and read, and if they touch different coloursm the song will alert the mistake.

Nick Gammon

Code: [Select]
int val = 20;

You are reading pin 20. Is that what you want? Does it even have a pin 20?


ahh is that it? no there no pin 20...there 5 analog pins, i want each analog pin to read a fix value for example so when the write and read touch each other they will make an specific sound
i how to do with digitalWrite and digitalRead, but when i touch, for example red with yellow i need to make another kind of sound, meaning an error

Nick Gammon

You want to read a fixed value? Afraid not. What you mean is, you want to read a value, and then check what that value is with an "if" statement. Try that.


thanks for the help, i am testing, then i will post the results

Go Up