#include #include "FastLED_RGBW.h" #define PIN_STRIP1 7 #define NUM_LEDS 4 CRGBW strip1[NUM_LEDS]; // FastLED with RGBW CRGB *strip1B = (CRGB *) &strip1[0]; #define PUL_P 12 #define DIR_P 11 #define ENA_P 10 #define MODE 9 #define CAMERA 3 //PD1 #define RED A0 #define GREEN A1 #define BLUE A2 #define WHITE A3 #define SP1 A4 #define SP2 A5 #define frameready_sensor 2 #define NUM_COUNTS 3 long delay_Micros = 20; // Set value long currentMicros = 0; long previousMicros = 0; int frame_ready = 1; //frame sensor variable int transport_ready = 1; //projector transport switch variable int REDval = 0; int GREENval = 0; int BLUEval = 0; int WHITEval = 255; int SPEED1val = 0; int SPEED2val = 0; int REDval_ant = 255; int GREENval_ant = 255; int BLUEval_ant = 255; int WHITEval_ant = 0; int motor_run; int motor_dir; int mydata[20]; // serial input buffer int mydata_temp[20]; // serial input buffer int frame_ready_ant = frame_ready; int count = 0; bool stop_count = 0; byte c; byte c_inc = 0; unsigned long time_frame_ready = millis(); void blink() { frame_ready = !digitalRead(frameready_sensor); } void search_frame() { digitalWrite(ENA_P, LOW); // Turn motor ON if serial says so digitalWrite(DIR_P, HIGH); while((count(strip1B, getRGBWsize(NUM_LEDS)); pinMode(PUL_P, OUTPUT); pinMode(DIR_P, OUTPUT); pinMode(ENA_P, OUTPUT); pinMode(CAMERA, OUTPUT); pinMode(MODE, INPUT_PULLUP); pinMode(frameready_sensor, INPUT_PULLUP); digitalWrite(CAMERA, HIGH); digitalWrite(PUL_P, HIGH); digitalWrite(DIR_P, LOW); digitalWrite(ENA_P, HIGH); for(int i=0; i=NUM_COUNTS)&&(frame_ready)) { WHITEval = map(analogRead(WHITE), 0, 1023, 0, 255); if(WHITEval!=WHITEval_ant) { for(int i=0; i0) { bool slow_ramp = false; bool fast_ant = false; if(mydata[3] != mydata_temp[3]) slow_ramp = true; if(mydata[6] == 0) fast_ant = true; for(int i=0; i<7; i++) mydata[i] = mydata_temp[i]; digitalWrite(DIR_P, (mydata[4])); // Set motor direction according to serial REDval = mydata[0]; GREENval = mydata[1]; BLUEval = mydata[2]; if((REDval!=REDval_ant)||(GREENval!=GREENval_ant)||(BLUEval!=BLUEval_ant)) { //WHITEval = (mydata[0] + mydata[1] + mydata[2])/3; for(int i=0; i=vel_rew; i--) { PORTB |= B00010000; delayMicroseconds(i); //Set Value PORTB &= B11101111; delayMicroseconds(i); //Set Value } } else if(mydata[3]==0) { for(int i=vel_rew; i<=500; i++) { PORTB |= B00010000; delayMicroseconds(i); //Set Value PORTB &= B11101111; delayMicroseconds(i); //Set Value } } } digitalWrite(ENA_P, (!mydata[3])); // Turn motor ON if serial says so } } c_inc=0; } else { mydata_temp[c_inc] = c; c_inc++; } } if((millis()-time_frame_ready)>=1000) { Serial.print("frame_ready "); Serial.print(1, DEC); Serial.println(); Serial.print("transport_ready "); Serial.print(transport_ready, DEC); Serial.println(); time_frame_ready = millis(); } if(mydata[3]==1) { if(mydata[6]==1) { PORTB |= B00010000; delayMicroseconds(time_speed); //Set Value PORTB &= B11101111; delayMicroseconds(time_speed); //Set Value } else if(mydata[6]==0) { PORTB |= B00010000; delayMicroseconds(vel_rew); //Set Value PORTB &= B11101111; delayMicroseconds(vel_rew); //Set Value } } else { WHITEval = map(analogRead(WHITE), 0, 1023, 0, 255); if(WHITEval!=WHITEval_ant) { for(int i=0; i=NUM_COUNTS)&&(frame_ready)) { time_speed = map(analogRead(SP1), 0, 1023, 0, 250); REDval = map(analogRead(RED), 0, 1023, 0, 255); GREENval = map(analogRead(GREEN), 0, 1023, 0, 255); BLUEval = map(analogRead(BLUE), 0, 1023, 0, 255); WHITEval = map(analogRead(WHITE), 0, 1023, 0, 255); if((REDval!=REDval_ant)||(GREENval!=GREENval_ant)||(BLUEval!=BLUEval_ant)||(WHITEval!=WHITEval_ant)) { for(int i=0; i