Pages: [1]   Go Down
Author Topic: Problem with analog read and write  (Read 553 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Write:
const int red = A4;

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

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

Read:
const int red = A4;
int val = 20;

void setup() {
pinMode(vermelho,INPUT);
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.
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 495
Posts: 19040
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
int val = 20;
...
Serial.println(analogRead(val));

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


Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 495
Posts: 19040
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged


Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Pages: [1]   Go Up
Jump to: