Go Down

Topic: Project 14 [tweak the arduino logo] (Read 1 time) previous topic - next topic

ShehabAldeen

when I start doing the project 14 I have faced a problem, after I have wrote my codes therewas an error in the processing program say as the Pic .
so what I should do ?

sh_aks

#1
Oct 02, 2015, 11:43 am Last Edit: Oct 02, 2015, 11:43 am by sh_aks
These codes should work without error.

Arduino 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.println(analogRead(A0)/4);
  delay(100);
}


Processing code:
Code: [Select]

import processing.serial.*;
Serial myPort;
PImage logo;
int bgcolor = 0;
void setup(){
  colorMode(HSB, 255);
  logo = loadImage("https://www.arduino.cc/en/pub/skins/arduinoWide/img/logo.png");
  size(logo.width, logo.height);
  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, bgcolor, 255);
  image(logo, 0, 0);
}



RajoAlfa

here :

size(logo.width, logo.height);

use numbers instead of variables, like the error says, like

size(200, 100);

jaspercmc

I've just tried it yesterday. Besides the size that "RajoAlfa" mentioned above.
Please modify this line as well:
myPort = new Serial(this, Serial.list()[0], 9600);
to
myPort = new Serial(this, "COM3", 9600);

Note: COM3 is what my Arduino using.

It works for me!! :)

cecero

#4
Nov 24, 2015, 09:52 pm Last Edit: Nov 25, 2015, 12:27 pm by cecero
I am using OS X 10.11.1.

The code the book presented didn't work for me. This is a summary of the changes I made so that it worked. 


Arduino 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(100);
}



Processing code:
Code: [Select]

import processing.serial.*;
Serial myPort;
PImage logo;
int bgcolor = 0;
void setup(){
  colorMode(HSB, 255);
  logo = loadImage("https://www.arduino.cc/en/pub/skins/arduinoWide/img/logo.png");
  size(400, 200);
  println("Avaliable serial ports:");
  println(Serial.list());
  myPort = new Serial(this, Serial.list()[1], 9600);
 
}
void draw(){
  if (myPort.available() > 0) {
    bgcolor = myPort.read();
    println(bgcolor);
  }
  background(bgcolor, bgcolor, 255);
  image(logo, 0, 0);
}




In Arduino code:
1. delay(1) to delay(100)

Processing code:
1. change image url
https://www.arduino.cc/en/pub/skins/arduinoWide/img/logo.png

2. change size() to constants
size(400, 200);

3. change myPort
myPort = new Serial(this, Serial.list()[1], 9600);

 


Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy