Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const int onecount = 52;
- const int othercount = 53;
- int metronome;
- #include <SoftwareSerial.h>
- #include <TimerOne.h>
- int metVal = 120;
- int mval;
- int delaycount = 0;
- void loop() {
- digitalWrite(othercount, LOW);
- digitalWrite(onecount, LOW);
- GETMetVAL();
- //GetmetVal should retrun the pot value to metronome
- //TimerOne interval change here
- Serial.println(metronome);
- }
- void setup() {
- Timer1.initialize(1000000); // set a timer of length 100000 microseconds (or 0.1 sec - or 10Hz => the led will blink 5 times, 5 cycles of on-and-off, per second)
- Timer1.attachInterrupt( RealMetronome ); // attach the service routine here
- Serial.begin(9600);
- }
- void RealMetronome()
- {
- if (delaycount >= 4) {
- delaycount = 1;
- } else {
- delaycount++;
- }
- if (delaycount == 1) {
- digitalWrite(othercount, LOW);
- digitalWrite(onecount, HIGH);
- } else {
- digitalWrite(onecount, LOW);
- digitalWrite(othercount, HIGH);
- }
- }
- void GETMetVAL() {
- switch (mval)
- {
- case 0 ... 1023:
- if (analogRead(A2) < 10) {
- metVal = 10;
- } else {
- mval = analogRead(A2);
- metronome = mval;
- }
- //Math should be placed here
- //metronome = (equation here)
- // then reset the TIMERONE interval in the main loop.
- break;
- default:
- metVal = 130;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement