hij moet gaan luisteren naar DCC prog commando's en POM commando's
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// DCC packet handler //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////void BasicAccDecoderPacket_Handler(int address, boolean activate, byte data){ // Convert NMRA packet address format to human address address -= 1; address *= 4; address += 1; address += (data & 0x06) >> 1; boolean enable = (data & 0x01) ? 1 : 0; for(int i=0; i<maxservos; i++) { if(address == accessory[i].address) //is dit een gezocht dcc addres? {#ifdef TESTSERIAL Serial.print("Basic addr: "); Serial.print(address,DEC); Serial.print(" activate: "); Serial.println(enable,DEC);#endif if (i == testdccservo) { digitalWrite(LED,HIGH); } if(enable) accessory[i].output = 1; else accessory[i].output = 0; } }}
void BasicAccDecoderPacket_Handler(int address, boolean activate, byte data){ address -= 1; address *= 4; address += 1; address += (data & 0x06) >> 1; boolean enable = (data & 0x01) ? 1 : 0; if( address == 1 ){ if(enable){ servoControl.gotoEndPos(1, 0); } else{ servoControl.gotoEndPos(1, 1); } }}
void buttonUpdate(){ static byte iButton; //Pointer to button to update static byte numButtons; //Counter for the number of buttons pressed byte servo = iButton / 2; //Pointer to effected servo byte modulo = iButton % 2; //which butto for that servo buttons[iButton].update(); //update the button state //button is pressed an is even (have priority over odd) if(buttons[iButton].read() == LOW && modulo == 0){ servoControl.gotoEndPos(servo, 0); //go to position A numButtons++; } //button is pressed and is odd, check if the even button isn't pressed else if(buttons[iButton].read() == LOW && modulo == 1 && buttons[iButton - 1].read() == HIGH){ servoControl.gotoEndPos(servo, 1); //go to position B numButtons++; } //Update button pointer for next call iButton++; if(iButton >= NrButtons){ iButton = 0; //Turn ArduinoLED on if button is pressed if(numButtons != 0){ digitalWrite(LedArduino, HIGH); numButtons = 0; } else{ digitalWrite(LedArduino, LOW); } }}
unsigned long tic; unsigned long toc; static unsigned long tictoc; static unsigned long tocMin, tocMax, tocAvg; servoControl.update(); //update all servo's tic = micros(); //check buttons for a press (one per call) buttonUpdate(); // <----- Gaat het om toc = micros(); toc -= tic; if(tocMin > toc){ tocMin = toc; } else if(tocMax < toc){ tocMax = toc; } if(tocAvg == 0){ tocAvg = toc; } else{ tocAvg += toc; tocAvg /= 2; } if( (millis() - tictoc) > 1000UL) { tictoc = millis(); Serial.print(tic); Serial.print(" "); Serial.print(toc); Serial.print(" "); Serial.print(tocMin); Serial.print(" "); Serial.print(tocMax); Serial.print(" "); Serial.println(tocAvg); tocMin = -1; tocMax = 0; tocAvg = 0; }