Go Down

Topic: Project 14: Tweak the arduino logo || Weird values (Read 1 time) previous topic - next topic

ItsKasper

Hi,

I am getting weird vlaues from my potentiometer.

This is my code:
Code: [Select]
void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
}

void loop() {
  // put your main code here, to run repeatedly:
  Serial.write(analogRead(A0)/4);
  delay(1);
}


And the processing code:
Code: [Select]
import processing.serial.*;
Serial myPort;
PImage logo;
int bgcolor = 0;
void setup(){
  colorMode(HSB, 255);
  logo = loadImage("http://arduino.cc/logo.png");
  size(170, 116);
  println("Avaliable serial ports:");
  println(Serial.list());
  myPort = new Serial(this, Serial.list()[0], 9600);
}
void draw(){
  if (myPort.available() > 0) {
    bgcolor = myPort.read();
    println(bgcolor);
  }
  background(bgcolor, 255, 255);
  image(logo, 0, 0);
}


I couldn't get logo.width and logo.height to work, so i just used 170 and 116.

The Arduino logo shows up but it stays red.

Thanks

sh_aks

Update Arduino code :
Present
Serial.write(analogRead(A0)/4);


Change:
Serial.print(analogRead(A0)/4);
OR
Serial.println(analogRead(A0)/4);

Should solve the problem.

sh_aks

Update the following lines of code in the processing code and the logo.width and logo.height will also work.


  logo = loadImage("https://www.arduino.cc/en/pub/skins/arduinoWide/img/logo.png");
  size(logo.width, logo.height);

this can be a temporary fix for you i guess.

RajoAlfa

just change this

myport= new Serial(this, Serial.list()[0], 9600);

the number 0, change it to the right port that your arduino is connected.
It didnt worked for me when it was 0, then i changed to 3(arduino was on COM3) didnt work either, 2 didnt work and 1 was the right one.

RRivoallan

I had the same issue than you, using Processing 3.

The solution is to use the "while" keyword instead of "if"  in the draw() function :

while (myPort.available() > 0) {
   bgcolor = myPort.read();
   println(bgcolor);
 }

Go Up