Hello everyone,
I can not transmit or receive PWM information, sent with analogWrite from Arduino and find it in Processing.
I used the Arduino Input example in Processing and I can get the information from the Arduino analog input and the Arduino digital outputs (the Arduino program is based on the standardFirmata skecth). But I can not get the PWM information from the Arduino output 9. I just receive the data 0.
Thank you for your lights!
Processing Program
import processing.serial.*;
import cc.arduino.*;
Arduino arduino;
color off = color(4, 79, 111);
color on = color(84, 145, 158);
void setup() {
size(470, 280);
// Prints out the available serial ports.
println(Arduino.list());
// Modify this line, by changing the "0" to the index of the serial
// port corresponding to your Arduino board (as it appears in the list
// printed by the line above).
arduino = new Arduino(this, Arduino.list()[4], 57600);
// Alternatively, use the name of the serial port corresponding to your
// Arduino (in double-quotes), as in the following line.
//arduino = new Arduino(this, "/dev/tty.usbmodem621", 57600);
// Set the Arduino digital pins as inputs.
for (int i = 0; i <= 13; i++)
arduino.pinMode(i, Arduino.INPUT);
}
void draw() {
background(off);
stroke(on);
// Draw a filled box for each digital pin that's HIGH (5 volts).
for (int i = 0; i <= 13; i++) {
if (arduino.digitalRead(i) == Arduino.HIGH)
fill(on);
else
fill(off);
rect(420 - i * 30, 30, 20, 20);
}
// Draw a circle whose size corresponds to the value of an analog input.
noFill();
for (int i = 0; i <= 5; i++) {
ellipse(280 + i * 30, 240, arduino.analogRead(i) / 16, arduino.analogRead(i) / 16);
ellipse(50, 240, arduino.analogRead(9) / 16, arduino.analogRead(9) / 16);
println(arduino.analogRead(9));
}
}
Arduino Program (just the end)
a=a+1;
float b = a/100;
int sensorValue = analogRead(A0);
// Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
float voltage = sensorValue * (5/ 1023.0);
int phi= map (voltage, 0, 5, 0, 180);
//// Converts the potar value as phase shift of the cosine wave
//TEST OUTPUT VALUE
digitalWrite (3, HIGH);
digitalWrite (8, HIGH);
analogWrite (ledPin, abs (100*cos (2*PI*b/10)));
analogWrite (ledPin2, abs (200*cos (2*PI*b/10-phi)));
Serial.println (b);
Serial.println (phi);
Serial.print ("fonction cos "); Serial.println(abs (100*cos (2*PI*b/100)));
Serial.print ("fonction lag "); Serial.println(abs (100*cos (2*PI*b/100- phi)));