// Beat Converter // This script is for the arduino. // Gijs Gieskes 2008 int analogIn0 = 0; int analogIn1 = 0; int onoff = 0; int devide = 0; unsigned long MIllisTime = 0; int interval = 64; unsigned long previousMillis = 0; int intervalAngle = interval * 10; unsigned long previousMillisAngle = 0; byte angle[] = {0,0}; boolean switcherAngle = false; byte angleOut = 33; int angleTcalc = 0; void setup() { pinMode(3, OUTPUT); pinMode(5, OUTPUT); pinMode(6, INPUT); digitalWrite(6, HIGH); Serial.begin(57600); } void loop() { MIllisTime = millis(); interval = analogRead(2)+1; analogIn0 = (analogRead(0)/2) - 255; analogIn0 = constrain(analogIn0, 0, 255); analogIn1 = analogRead(1); analogIn1 = map(analogIn1, 0, 1023, 0, angleOut); analogIn1 = constrain(analogIn1, 0, 255); if (MIllisTime - previousMillis > interval) { previousMillis = MIllisTime; if(onoff == HIGH){serialPrintClock();} //stuur maar een keer onoff = LOW; } angleTcalc = analogIn0 + (angleOut - analogIn1); angleTcalc = constrain(angleTcalc, 0, 255); if(angleTcalc > angleOut){ //if angleTcalc is higher the angleOut, keep onoff high previousMillis = MIllisTime; //reset previousMillis, so onoff remains HIGH when angleTcalc has gone over the threshold. if(onoff == LOW){serialPrintClock();} //stuur maar een keer onoff = HIGH; } //capture the highest value 2 time if(analogIn0 > angle[0]){ angle[0] = analogIn0; } if(analogIn0 > angle[1]){ angle[1] = analogIn0; } if (MIllisTime - previousMillisAngle > 2000) { previousMillisAngle = MIllisTime; switcherAngle = !switcherAngle; if(switcherAngle){ //switch back and forth between captured values, so there are no gaps angleOut = angle[0]; angleOut = min(angleOut, 255); angle[0] = 0; }else{ angleOut = angle[1]; angleOut = min(angleOut, 255); angle[1] = 0; } } digitalWrite(3 ,onoff); if(digitalRead(6) == LOW){ digitalWrite(5 ,onoff); }else{ digitalWrite(5 , LOW); } } void serialPrintClock(){ for(byte i=0; i<24; i++){ Serial.print(56, BYTE); } }