..γενικά έχουμε δοκιμάσει-καταφέρει να ελέγξουμε μέχρι 3 arduino boards από ένα Pc (ένα-ένα το κάθε LED).. αλλά το πρόβλημα είναι πάλι ο καθορισμός των πρώτων LEDs της κάθε σειράς..
arduino code:
int ledPin[] = {1,2,3,4,5,6,7,8,9,10,11,12,13};
int procByte[13]; //incoming byte
void setup()
{
// initialize the serial communication:
Serial.begin(9600);
// initialize the ledPin as an output:
for (int i=0; i<13; i++) {
pinMode(ledPin[i], OUTPUT);
}
}
void loop() {
// check if data has been sent from the computer:
if (Serial.available()>13) {
for (int i=0; i<13; i++) {
// read each byte
procByte[i] = Serial.read();
// pass the value to each pin
analogWrite(ledPin[i], procByte[i]);
}
}
}
processing code:
import processing.serial.*;
Serial port;
void setup() {
size(500, 150);
port = new Serial(this, "COM15", 9600);
background(255);
stroke (0);
line (250, 0, 250, 150);
}
void draw() {
if (mouseX <250 ) {
port.write(255); //first (??) ledPin on
port.write(0); //other ledPins off
port.write(0);
port.write(0);
port.write(0);
port.write(0);
port.write(0);
port.write(0);
port.write(0);
port.write(0);
port.write(0);
port.write(0);
port.write(0);
}
else if (mouseX < 500 ) {
port.write(0); //first(??) ledPin off
port.write(255); //this led on
port.write(0);
port.write(0);
port.write(0);
port.write(255); //this led on
port.write(0);
port.write(0);
port.write(0);
port.write(0);
port.write(0);
port.write(0);
port.write(0);
}
}
Δεν υπάρχουν σχόλια:
Δημοσίευση σχολίου