/* * Handle note-on messages * Precondition: 1 <= channel <= 16, 0 <= pitch < 128, 0 <= velocity < 128 */ void HandleNoteOn(byte channel, byte pitch, byte velocity) { //If zero velocity, turn the note off if (velocity == 0) { HandleNoteOff(channel, pitch, velocity); return; } double freq = frequencyTable[pitch]; if (useSerial) { //Print a message to Serial Monitor Serial.println("NOTE ON"); Serial.println("Channel: " + String(channel) + ", Pitch: " + String(pitch) + ", Velocity: " + String(velocity)); Serial.println("Computed Frequency: "+String(freq)+"Hz"); } if (useLCD) { //Print a message to the LCD clearLCD(); printToLCD(0,0,"On F="+String(freq)+"Hz"); printToLCD(0,1,"P="+String(pitch)+", V="+String(velocity)); } ledOff(); //just to be safe DueTimer timer = Timer.getAvailable(); timer.attachInterrupt(blinkLED); timer.setFrequency(freq); timer.start(); activeTimers[pitch] = timer; }
/* * Handle note-off messages * If sustain is not on, kill the note * Otherwise, toggle the flag that puts the timers * into sustain mode */ void HandleNoteOff(byte channel, byte pitch, byte velocity) { if (useSerial) { //Print a message to Serial Monitor Serial.println("NOTE OFF"); Serial.println("Channel: " + String(channel) + ", Pitch: " + String(pitch) + ", Velocity: " + String(velocity)); } if (useLCD) { //Print a message to the LCD clearLCD(); printToLCD(0,0,"Off"); printToLCD(0,1,"P="+String(pitch)+", V="+String(velocity)); } DueTimer timer = activeTimers[pitch]; //Error prone, if a NoteOff is sent for some note that wasn't turned on with NoteOn timer.detachInterrupt(); //Also stops the timer activeTimers[pitch] = NULL; //Clear the spot in the activeTimers array }
//Potentially leaves free-running timers void HandleContinue() { if (useSerial) { Serial.println("CONTINUE"); } if (useLCD) { //Print to LCD clearLCD(); printToLCD(0,0,"Restarting..."); printToLCD(0,1,"(Could crash)"); } Timer0.start(); Timer1.start(); Timer2.start(); Timer3.start(); Timer4.start(); Timer5.start(); Timer6.start(); Timer7.start(); Timer8.start(); }
void HandleStop() { if (useSerial) { Serial.println("STOP"); } if (useLCD) { //Print to LCD clearLCD(); printToLCD(0,0,"Stop!"); printToLCD(0,1,"Hammertime"); } Timer0.stop(); Timer1.stop(); Timer2.stop(); Timer3.stop(); Timer4.stop(); Timer5.stop(); Timer6.stop(); Timer7.stop(); Timer8.stop(); }
//Reset EVERYTHING void HandleSystemReset() { if (useSerial) { Serial.println("SYSTEM RESET"); } if (useLCD) { //Print to LCD clearLCD(); printToLCD(0,0,"Resetting"); printToLCD(0,1,"System"); } Timer0.detachInterrupt(); Timer1.detachInterrupt(); Timer2.detachInterrupt(); Timer3.detachInterrupt(); Timer4.detachInterrupt(); Timer5.detachInterrupt(); Timer6.detachInterrupt(); Timer7.detachInterrupt(); Timer8.detachInterrupt(); activeTimers = {NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL}; }
void RoverNavigator::loopAt1Hz() { _gps->location(&_lat, &_lon, &_age); #if ENABLE_LCD printToLCD(); #endif #if MANUAL_PID_TUNING configurePIDConstants(); #endif #if DEBUG_LOG debugLog(); #endif }