//#include //#include int dirbpin = 12; // Direction pin for motor B is Digital 12 int speedbpin = 9; // Speed pin for motor B is Digital 9 (PWM) int speed = 42; int dir = 1; int light_counter = 0; int icount = 0; #define IR_LED_PIN 4 #define IR_DETECT_PIN 2 #define FLASH_LED_PIN 13 #define INITIAL_SPEED 60 #define SWITCH_PIN 3 #define INIT_TIMER_COUNT 6 #define RESET_TIMER2 TCNT2 = INIT_TIMER_COUNT void setup() { Serial.begin(9600); // set up Serial library at 9600 bps Serial.println("Motor test!"); pinMode(SWITCH_PIN, INPUT); // Turn on Light digitalWrite(FLASH_LED_PIN, 1); pinMode(dirbpin, OUTPUT); // Make it spin and flash for a second digitalWrite(dirbpin, dir); // set direction analogWrite(speedbpin, INITIAL_SPEED); // set speed (PWM) delay(1000); digitalWrite(FLASH_LED_PIN, 0); delay(100); digitalWrite(FLASH_LED_PIN, 1); delay(100); digitalWrite(FLASH_LED_PIN, 0); delay(100); digitalWrite(FLASH_LED_PIN, 1); delay(100); digitalWrite(FLASH_LED_PIN, 0); delay(100); digitalWrite(FLASH_LED_PIN, 1); delay(100); digitalWrite(FLASH_LED_PIN, 0); delay(100); } // function: ledOn() - Turnds the strobe LED on void ledOn() { detachInterrupt(0); Serial.println("Interrupt ledOn()"); digitalWrite(FLASH_LED_PIN, 1); light_counter = 0; } // function: ledOff() - Turns the strobe LED off void ledOff() { Serial.println("Interrupt ledOff()"); digitalWrite(FLASH_LED_PIN, 0); attachInterrupt(0, ledOn, FALLING); Serial.println("ledOff return"); } // functions: potRange - Calculates a return value based on passed paramaters // minval: The minimum return value (what to return when its all the way down) // maxval: The maximum return value (what to return when its all the way up) int potRange(int minval, int maxval, int potPin) { int range = maxval - minval; int percentage = (1024 - analogRead(potPin))*100/1000; int scaled = range * percentage; int retVal = minval + scaled/100; if (retVal <= minval) { retVal = 0; } return retVal; } // Main Loop void loop() { int onFlash = 900; static int washigh = 0; // Remembers the last state of the IR receiver // Read the speed pot and set the on-time for the strobe based on speed. // As the disk spins faster, the image will smear if we leave the // strobe on for too long so we want to modulate the strobe on-time. speed = potRange(20, 180, 0); onFlash -= 3*speed; // Here is another method for calculating how long to keep the flash on //onFlash = 400 - speed; analogWrite(speedbpin, speed); // ------------------------------------------------------------------- // Auto Sync // ------------------------------------------------------------------- if (digitalRead(SWITCH_PIN) == HIGH) { if (LOW == digitalRead(2)) { if (0 < washigh) { washigh = 0; for (int i=0; i