Skip to content

Commit

Permalink
Arduino changes, correct pin numbers.
Browse files Browse the repository at this point in the history
  • Loading branch information
smukkejohan committed Oct 17, 2012
1 parent f1dbe2f commit e3529ca
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 31 deletions.
84 changes: 58 additions & 26 deletions arduino/chaos_flowcontrol/chaos_flowcontrol.ino
Original file line number Diff line number Diff line change
Expand Up @@ -30,29 +30,61 @@ int airRegulatorPins [CHANNEL_NUM];
void setup() {
Serial.begin(9600); // opens serial port, sets data rate to 9600 bps
inputString.reserve(200);


waterValvePins[0] = 1;
waterValvePins[1] = 2;
waterValvePins[2] = 3;

airValvePins[0] = 1;
airValvePins[1] = 2;
airValvePins[2] = 3;
pinMode(8, OUTPUT);
pinMode(12, OUTPUT);
pinMode(13, OUTPUT);

waterValvePins[0] = 8;
waterValvePins[1] = 12;
waterValvePins[2] = 13;

pinMode(2, OUTPUT);
pinMode(4, OUTPUT);
pinMode(7, OUTPUT);

airValvePins[0] = 2;
airValvePins[1] = 4;
airValvePins[2] = 7;

pinMode(3, OUTPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);

pumpPins[0] = 3;
pumpPins[1] = 5;
pumpPins[2] = 6;

pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
pinMode(11, OUTPUT);

airRegulatorPins[0] = 9;
airRegulatorPins[1] = 10;
airRegulatorPins[2] = 11;


for(int i=0; i< CHANNEL_NUM; i++) {

setAirPressure(i, 40);


openWater(i);
closeAir(i);
delay(2000);
closeWater(i);
openAir(i);
delay(2000);
openWater(i);
closeAir(i);
delay(2000);

}


pumpPins[0] = 1;
pumpPins[1] = 2;
pumpPins[2] = 3;

airRegulatorPins[0] = 1;
airRegulatorPins[1] = 2;
airRegulatorPins[2] = 3;
}

char inData[80];
char parsedData[80];
byte index = 0;

void loop() {

// send data only when yoSu receive data:
Expand Down Expand Up @@ -85,31 +117,31 @@ void loop() {
} else {
if (c=='c') {
channel = value;
Serial.println("Set channel to " + String(value));
//Serial.println("Set channel to " + String(value));
} else if (c=='p') {
setAirPressure(channel, value);
Serial.println("Set air pressure to " + String(value));
//Serial.println("Set air pressure to " + String(value));
} else if (c=='s') {
setWaterPressure(channel, value);
Serial.println("Set water pressure to " + String(value));
//Serial.println("Set water pressure to " + String(value));
} else if (c=='a') {
if (value==1) {
openAir(channel);
Serial.println("Open air valve");
//Serial.println("Open air valve");
} else if (value == 0) {
closeAir(channel);
Serial.println("Close air valve");
//Serial.println("Close air valve");
}
} else if (c=='w') {
if (value==1) {
openWater(channel);
Serial.println("Open water valve");
//Serial.println("Open water valve");
} else if (value == 0) {
closeWater(channel);
Serial.println("Close water valve");
//Serial.println("Close water valve");
}
}

value = 0;
}
}
Expand Down
22 changes: 17 additions & 5 deletions src/flowControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ void flowControl::setup(){

arduino[0].enumerateDevices();
arduino[0].setup("/dev/tty.usbmodemfa131", 9600);
arduino[1].setup("/dev/tty.usbmodemfa131", 9600);
arduino[0].setVerbose(true);

for (int i = 0; i < NUM_CHANNELS; i++) {
Expand Down Expand Up @@ -89,10 +90,21 @@ void flowControl::closeAirValve(Channel * c) {
void flowControl::updateChannel(Channel * c) {
// data format is channel number int; air pressure float 0-1, water pressure float 0-1, air open bool, water open bool,

sendValue('c', c->i, &arduino[0]);
sendValue('p', ofMap(c->airPressure, 0, 1, 0, 255), &arduino[0]);
sendValue('s', ofMap(c->waterPressure, 0, 1, 0, 255), &arduino[0]);
sendValue('a', c->airOpen, &arduino[0]);
sendValue('w', c->waterOpen, &arduino[0]);
int ci;
int ard = 0;

if (c->i > 2) {
ci = c->i - 3;
ard = 1;
} else if (c->i ) {
ci = c->i - 6;
ard = 2;
}

sendValue('c', ci, &arduino[ard]);
sendValue('p', ofMap(c->airPressure, 0, 1, 0, 255), &arduino[ard]);
sendValue('s', ofMap(c->waterPressure, 0, 1, 0, 255), &arduino[ard]);
sendValue('a', c->airOpen, &arduino[ard]);
sendValue('w', c->waterOpen, &arduino[ard]);

}

0 comments on commit e3529ca

Please sign in to comment.