Advertisement
Guest User

Cleaner bare bones Metronome.

a guest
Apr 5th, 2015
276
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.38 KB | None | 0 0
  1. const int onecount = 52;
  2. const int othercount = 53;
  3. int metronome;
  4. #include <SoftwareSerial.h>
  5. #include <TimerOne.h>
  6. int metVal = 120;
  7. int mval;
  8. int delaycount = 0;
  9.  
  10.  
  11. void loop() {
  12.   digitalWrite(othercount, LOW);
  13.   digitalWrite(onecount, LOW);
  14.  
  15.  
  16.   GETMetVAL();
  17.  
  18.   //GetmetVal should retrun the pot value to metronome
  19.  
  20.   //TimerOne interval change here
  21.  
  22.  
  23.   Serial.println(metronome);
  24. }
  25.  
  26. void setup() {
  27.   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)
  28.   Timer1.attachInterrupt( RealMetronome ); // attach the service routine here
  29. Serial.begin(9600);
  30. }
  31.  
  32. void RealMetronome()
  33. {
  34.  
  35.   if (delaycount >= 4) {
  36.     delaycount = 1;
  37.   } else {
  38.     delaycount++;
  39.   }
  40.   if (delaycount == 1) {
  41.     digitalWrite(othercount, LOW);
  42.     digitalWrite(onecount, HIGH);
  43.  
  44.   } else {
  45.  
  46.     digitalWrite(onecount, LOW);
  47.     digitalWrite(othercount, HIGH);
  48.  
  49.   }
  50. }
  51.  
  52. void GETMetVAL() {
  53.  
  54.  
  55.   switch (mval)
  56.   {
  57.  
  58.     case 0 ... 1023:
  59.  
  60.       if (analogRead(A2) < 10) {
  61.         metVal = 10;
  62.       } else {
  63.         mval = analogRead(A2);
  64.        metronome = mval;
  65.       }
  66.       //Math should be placed here
  67.       //metronome = (equation here)
  68.       // then reset the TIMERONE interval in the main loop.
  69.       break;
  70.     default:
  71.       metVal = 130;
  72.   }
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement