//-Tittle:.......... Scanning Light Spectrometer----------------------------------- //-By:.............. Kenneth B. Moore---------------------------------------------- //-Date:............ 26th-May-2014------------------------------------------------- //--------------------------------------------------------------------------------- //--------------------------------------------------------------------------------- byte ledPin[] = {4, 5, 6, 7, 8, 9, 10,11,12,13}; // Create array for LED pins int ledDelay; // delay between changes int direction = 1; // set the initial direction of the indicator LEDs int currentLED = 0; // zeros the count for the position of the LED int x = 0; int row = 0; unsigned long changeTime; // variable to hold the value of the time taken for the LED change int potPin = 2; // select the input pin for the potentiometer int delayData = 80; //--------------------------------------------------------------------------------- #include Servo servoMain; // Define our Servo int servoCount=0; int servoMove=0; //--------------------------------------------------------------------------------- void setup() { Serial.begin(128000); // opens serial port, sets data rate128000 bps Serial.println("CLEARDATA"); //clears any residual data Serial.println("LABEL,Time,Pin,Light Level"); //set the headings for the data transfer to excel servoMain.attach(13); //Set pin 13 as then signal pin for the servo for (int x=0; x<10; x++) { // set all pins to output pinMode(ledPin[x], OUTPUT); } changeTime = millis(); } //---------------------------------------------------------------------------------- void loop() { ledDelay = analogRead(potPin); // read the value from the pot if ((millis() - changeTime) > ledDelay) { // if it has been ledDelay ms since last change changeLED(); changeTime = millis(); } } //--------------------------------------------------------------------------------- void changeLED() { servoCount=servoCount+1; // counts 18 light changes before allowing the servo to move to the next possition if (servoCount>=18) { // test the servo loop if greater than or equal to 18 it starts servoMain.write(servoMove); // move servo to next possition servoMove=servoMove+1; // increase the servo possition setting for next time if(servoMove>=20) { // tests to see if servo has reached 48 degrees rotation servoMove=0; // at 48 degrees zer the possition setting - next time loop executed the servo // will move to 0 degrees and start again } servoCount=servoCount+1; // increase the servo count for this loop as the loop starts at 18 this will push it to 19 if(servoCount>=19){ // test the servo loop to see if it is at 19 servoCount=0; // if at 19 zero the count ready to start again } } for (int x=0; x<10; x++) { // turn off all LED's digitalWrite(ledPin[x], LOW); } digitalWrite(ledPin[currentLED], HIGH); // turn on the current LED currentLED += direction; // increment by the direction value //-------------------------------------------------------------------------------- // change direction if we reach the end if (currentLED == 9) { direction = -1; } if (currentLED == 0) { direction = 1; } //-------------------------------------------------------------------------------- Serial.print("DATA,TIME,"); Serial.print(currentLED); Serial.print(","); Serial.println(ledDelay); //-------------------------------------------------------------------------------- row++; x++; delay (delayData); }