Pages: [1]   Go Down
Author Topic: reading joystick code error  (Read 534 times)
0 Members and 1 Guest are viewing this topic.
Portsmouth UK
Offline Offline
Newbie
*
Karma: 0
Posts: 10
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

 
i took this code from the aruino website,

Code:
/* Read Jostick
  * ------------
  *
  * Reads two analog pins that are supposed to be
  * connected to a jostick made of two potentiometers
  *
  * We send three bytes back to the comp: one header and two
  * with data as signed bytes, this will take the form:
  * Jxy\r\n
  *
  * x and y are integers and sent in ASCII
  *
  * http://www.0j0.org | http://arduino.berlios.de
  * copyleft 2005 DojoDave for DojoCorp
  */

 int ledPin = 13;
 int joyPin1 = 0;                 // slider variable connecetd to analog pin 0
 int joyPin2 = 1;                 // slider variable connecetd to analog pin 1
 int value1 = 0;                  // variable to read the value from the analog pin 0
 int value2 = 0;                  // variable to read the value from the analog pin 1

 void setup() {
  pinMode(ledPin, OUTPUT);              // initializes digital pins 0 to 7 as outputs
  beginSerial(9600);
 }

 int treatValue(int data) {
  return (data * 9 / 1024) + 48;
 }

 void loop() {
  // reads the value of the variable resistor
  value1 = analogRead(joyPin1);   
  // this small pause is needed between reading
  // analog pins, otherwise we get the same value twice
  delay(100);  
  // reads the value of the variable resistor
  value2 = analogRead(joyPin2);   

  digitalWrite(ledPin, HIGH);           
  delay(value1);
  digitalWrite(ledPin, LOW);
  delay(value2);
  serialWrite('J');
  serialWrite(treatValue(value1));
  serialWrite(treatValue(value2));
  serialWrite(10);
  serialWrite(13);
 }

and it gives this error code when i try to verify

sketch_jul20a.cpp: In function 'void setup()':
sketch_jul20a:24: error: 'beginSerial' was not declared in this scope
sketch_jul20a.cpp: In function 'void loop()':
sketch_jul20a:44: error: 'serialWrite' was not declared in this scope


can anyone advise me on what i need to do to correct it?

many thanks
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 240
Posts: 24454
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

That's really old code, I'm guessing.
Code:
Serial.begin(9600);
is the correct form.
Code:
Serial.print
in other cases.

Can you provide links to where you found it please?

(Never tried to read incense myself)
« Last Edit: July 20, 2012, 03:56:50 pm by AWOL » Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Portsmouth UK
Offline Offline
Newbie
*
Karma: 0
Posts: 10
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

http://www.arduino.cc/en/Tutorial/JoyStick

here. thanks for replying  smiley
Logged

Portsmouth UK
Offline Offline
Newbie
*
Karma: 0
Posts: 10
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

After fixing that now i have this part
Code:
serialWrite('J');

producing error code

sketch_jul20a.cpp: In function 'void loop()':
sketch_jul20a:44: error: 'serialWrite' was not declared in this scope

any ideas?
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 240
Posts: 24454
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
Serial.print('J');
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Portsmouth UK
Offline Offline
Newbie
*
Karma: 0
Posts: 10
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

thanks alot. massive help, i am seeing a trend now and fixed the rest of the code. smiley
Logged

Pages: [1]   Go Up
Jump to: