Browse Source

atomizers timer

develop
Carmine De Rosa 6 years ago
parent
commit
30f7237c3e
  1. 55
      arduino/arduino.ino
  2. 6
      ephimera/ephimera.pde
  3. 1
      ephimera/frames.pde
  4. 28
      ephimera/serial.pde

55
arduino/arduino.ino

@ -3,13 +3,17 @@
Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver();
#define SERVOMIN 350 // this is the 'minimum' pulse length count (out of 4096)
#define SERVOMAX 385 // this is the 'maximum' pulse length count (out of 4096)
#define SERVOMIN 330 // this is the 'minimum' pulse length count (out of 4096) - increasing SERVOMIN decrease speed
#define SERVOMAX 390 // this is the 'maximum' pulse length count (out of 4096)
const char HEADER = 'H';
const char A_TAG = 'M';
const char B_TAG = 'X';
const int TOTAL_BYTES = 10 ; // the total bytes in a message
int atomPins[] = {2,3,4,5,6,7,8,9};
int currentValue = 0;
int values[] = {0,0,0,0,0,0,0,0,0};
int values[] = {0,0,0,0,0,0,0,0};
int cycle = 0;
void setup() {
@ -17,8 +21,11 @@ void setup() {
for(int i=0; i<8; i++) {
pinMode(atomPins[i], OUTPUT);
pwm.setPWM(i, 0, ((SERVOMAX-SERVOMIN)/2)+SERVOMIN);
}
pinMode(13, OUTPUT);
digitalWrite(13, HIGH);
pwm.begin();
pwm.setPWMFreq(60); // Analog servos run at ~60 Hz updates
@ -40,33 +47,49 @@ void setServoPulse(uint8_t n, double pulse) {
}
void loop() {
if(Serial.available()){
int incomingValue = Serial.read();
values[currentValue] = incomingValue;
cycle = 0;
currentValue++;
if(currentValue > 8){
currentValue = 0;
for(int i=0; i<8; i++) {
values[i] = 0;
}
cycle = 0;
if(Serial.available() >= TOTAL_BYTES) {
if( Serial.read() == HEADER) {
char tag = Serial.read();
if(tag == A_TAG) {
for(int i=0; i<8; i++) {
values[i] = Serial.read();
}
}
while(cycle < 8) {
while(cycle != 8) {
for(int i=0; i<8; i++) {
Serial.print(values[i]);
Serial.print(" ");
if(values[i]>0) {
values[i]--;
digitalWrite(atomPins[i], HIGH);
pwm.setPWM(i, 0, SERVOMIN);
//pwm.setPWM(i, 0, SERVOMIN);
if(values[i]==0) {
digitalWrite(atomPins[i], LOW);
pwm.setPWM(i, 0, ((SERVOMAX-SERVOMIN)/2)+SERVOMIN);
cycle++;
digitalWrite(atomPins[i], LOW);
//pwm.setPWM(i, 0, ((SERVOMAX-SERVOMIN)/2)+SERVOMIN);
}
} else {
//cycle++;
//digitalWrite(atomPins[i], LOW);
}
}
delay(100);
}
Serial.println("");
delay(500);
//digitalWrite(13, LOW);
}
}
}
}

6
ephimera/ephimera.pde

@ -9,10 +9,11 @@ PImage img;
int videoWidth = 640;
int videoHeight = 480;
int sending = 0;
void setup() {
size(640, 480, P2D);
frameRate(10);
frameRate(2);
colorMode(HSB, 100, 100, 100);
String portName = Serial.list()[0];
@ -25,13 +26,12 @@ void setup() {
}
void draw() {
ephPercentage();
//ephPercentage();
}
void keyPressed() {
if (key == 'S' || key == 's') {
video.stop();
printArray(colorValues);
makePicture();
}
if (key == 'B' || key == 'b') {

1
ephimera/frames.pde

@ -1,6 +1,7 @@
void makePicture() {
saveFrame("data/shot.gif");
img = loadImage("shot.gif");
ephPercentage();
ephSerial();
}

28
ephimera/serial.pde

@ -1,3 +1,6 @@
public static final char HEADER = 'H';
public static final char A_TAG = 'M';
public static final char B_TAG = 'X';
void ephSerial() {
@ -6,6 +9,27 @@ void ephSerial() {
print(colorByteValues[i] + "\t");
}
println("");
port.write(colorByteValues);
printArray(colorByteValues);
sendMessage(A_TAG, colorByteValues);
//sendMessage(A_TAG, 5,55,0,33,0,55,0,55);
//printArray(colorByteValues);
}
void sendMessage(char tag, byte[] cbv){
// send the given index and value to the serial port
port.write(HEADER);
port.write(tag);
for(int i=0; i<cbv.length; i++) {
port.write(cbv[i]);
}
}
void serialEvent(Serial p) {
// handle incoming serial data
String inString = port.readStringUntil('\n');
if(inString != null) {
print( inString ); // echo text string from Arduino
}
}

Loading…
Cancel
Save