Hi, newbie question here. i've been trying to get a correct output format from my arduino uno. Here's my sketch :
int redPotPin = A0;
int red;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
red = map(analogRead(redPotPin), 0, 1023, 0, 255);
String txt = red + ";";
Serial.print(txt);
delay(250);
}
I'm simply trying to get a value from a potentiometer (i'm planning to use three). And then read that value from a java application, which will change the background color of the frame from black (when the value is 0) up to red (when the value is 255).
Doing map from 0-1023 to 0-255 is an awfully inefficient way of shifting right by 2. Also, why bother using String object? Why not just print the number and the print the semicolon?
const int redPotPin = A0;
int red;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
red = map(analogRead(redPotPin), 0, 1023, 0, 255);
Serial.print (red);
Serial.print (";");
delay(250);
}