Buongiorno a tutti, sto facendo un programma per il monitoraggio di vari sensori.
Arduino legge 3 valori da tre sensori che non ho ancora quindi per ora sul void loop() ho creato una variabile incrementale che continua a inviare un numero crescente.
Dalla parte Processing ho creato un interfaccia grafica con controlp5
Ora sono in alto mare non riesco a proseguire:
Cosa non riesco a fare:
ARDUINO:
Inviare un array di tre sensori (valori) tramite seriale e riceverli in processing.
PROCESSING:
Collegare le variabili prese in seriale all' oggetto knob dell' interfaccia per far si che si muova la "lancetta" del manometro.
Sostanzialmente non riesco a mandare tre valori diverso da arduino a processing e lato processing non ho idea di come pescare i valori e metterli nel oggetto per far si che si muova la lancetta.
Spero che qualcuno mi possa aiutare perchè non riesco a ritrovare la strada =(
ARDUINO:
const int analogInPin = A0; // Analog input pin that the potentiometer is attached to
const int analogOutPin = 9; // Analog output pin that the LED is attached to
int sensorValue = 0; // value read from the pot
int outputValue = 0; // value output to the PWM (analog out)
void setup() {
// initialize serial communications at 9600 bps:
Serial.begin(9600);
}
void loop() {
// read the analog in value:
sensorValue = analogRead(analogInPin);
// map it to the range of the analog out:
outputValue = map(sensorValue, 0, 1023, 0, 255);
// change the analog out value:
analogWrite(analogOutPin, outputValue);
// print the results to the serial monitor:
Serial.print("sensor = " );
Serial.print(sensorValue);
Serial.print("\t output = ");
Serial.println(outputValue);
// wait 2 milliseconds before the next loop
// for the analog-to-digital converter to settle
// after the last reading:
delay(2);
}
PROCESSING:
import processing.serial.*;
import controlP5.*; // import controlP5 library
ControlP5 controlP5; // controlP5 object
Serial myPort; // The serial port:
PFont myFont; // The display font:
String inString; // Input string from serial port:
int lf = 10; // ASCII linefeed
int deg, val;
int myColorBackground = color(0,0,0);
Knob myKnob1;
Knob myKnob2;
Knob myKnob3;
int knobValue = 100;
void setup() {
size(640,480);
smooth(); //ControlP5
controlP5 = new ControlP5(this); //ControlP5
myKnob1 = controlP5.addKnob("PrexOlio",0,360,0,10,10,200);
myKnob2 = controlP5.addKnob("TempOlio",0,360,0,10,240,200);
myKnob3 =controlP5.addKnob("PrexTurbo",0,360,0,250,40,380);
println(Serial.list());
myPort = new Serial(this, Serial.list()[4], 9600);
myPort.bufferUntil(lf);
}
void draw() {
background(myColorBackground);
text("Punto GT 1.4 Turbo", 270,10);
text("Lettura: " + inString, 70,235);
text("Lettura: " + inString, 70,465);
text("Lettura: " + inString, 400,445);
}
void serialEvent(Serial p) {
inString = p.readString();
}
Grazie a tutti