Home \ Help \ Search \ Login RSS

Welcome, Guest. Please Login

This forum is now READ-ONLY! Please visit http://forum.wiring.co/ for the new forum.

Wiring ForumProgramming Questions & HelpPrograms › Serial.print in Wiring 15 & 16, mac using Leopard

Page Index Toggle Pages: 1
Serial.print in Wiring 15 & 16, mac using Leopard (Read 2215 times)
06/14/08 at 23:12:19

geo12   Offline
YaBB Newbies

Posts: 1
*
 
I'm having problems with the Serial.print(someValue, DEC) method in Wiring 15 and 16 on the mac with Leopard OS X. The Serial.print method works fine in Wiring 14, but in both 15 and 16, I get gibberish in the Serial Monitor window instead of the expected decimal value. Has the Serial.print method changed in the most recent versions?

Here's my complete code; it's code just slightly modified from Tom Igoe's "Making Things Talk" book:

int leftSensor = 0;
int rightSensor = 1;
int resetButton = 2;
int serveButton = 3;

int leftValue = 0;
int rightValue = 0;
int reset = 0;
int serve = 0;


void setup() {

  Serial.begin(9600);
  pinMode(resetButton, INPUT);
  pinMode(serveButton, INPUT);
}

void loop() {
 
  leftValue = analogRead(leftSensor);
  leftValue = scaleValue(leftValue, 0, 1024);
  rightValue = analogRead(rightSensor);
  rightValue = scaleValue(rightValue, 195, 755);
  reset = digitalRead(resetButton);
  serve = digitalRead(serveButton);
 
 
  Serial.print(leftValue, DEC);
  Serial.print(".");
  Serial.print(rightValue, DEC);
  Serial.print(".");
  Serial.print(reset, DEC);
  Serial.print(".");
  Serial.println(serve,DEC);
 
}


int scaleValue(int x, int low, int high) {
return (int)constrain(255 * ((float) (x - low)/(float)(high-low)),1,255);
}
« Last Edit: 06/15/08 at 13:55:44 by geo12 »  
IP Logged
 
Page Index Toggle Pages: 1