// PPM Encoder Analog Add-ons for Devo7e // For use with Digispark // J. Diehl 12/07/2015 // Based on a sketch by Ian Johnston 29/04/2010 // modified by Epyon and Cereal_Killer // Version 4.0 // Low cost way to add extra POT's to any radio that accepts PPM input for <$15 // using a Digispark, 2 POT's, and a 3-way and 2-way switch. Visit DeviationTX.com for info. // 5k POT's on JP3-0 and -3 // 3-way (On-off-On) switch on JP3-2 and-4 // 2-way (On-off) switch on JP3-5 // PPM output on JP3-2 // PPM inout to tip of 3.5 mono jack, this is the black wire on your Devo 7E DSC port int potPin_A1 = 2; //Declare potPin_A1 to be analog A1, pin 2 - no conflicts int potPin_A2 = 4; //Declare potPin_A2 to be analog A2, pin 4 - used in USB int AI_Raw_A1; // Analog In raw var - 0->1023 int AI_Raw_A2; // Analog In raw var - 0->1023 byte swPin_D1 = 0; //Declare swPin_D1 to be Digital pin pin 0 - no conflicts byte swPin_D2 = 3; //Declare swPin_D2 to be Digital pin pin 3 - used in USB byte swPin_D3 = 5; //Declare swPin_D3 to be Digital pin pin 5 - also NRESET int outPinPPM = 1; // Declare ppmPin to be pin pin 1; LED is on this line int Fixed_uS = 300; // PPM frame fixed LOW phase int pulseMin = 750; // pulse minimum width minus start in uS int pulseMax = 1700; // pulse maximum width in uS int pulseMid = pulseMin + (pulseMax - pulseMin) / 2; float adjustRng = ( pulseMax - pulseMin ) / 1023.0; // adjust range from 0-1023 int A1_uS = pulseMin; // Analog 1 uS var int A2_uS = pulseMin; // Analog 2 uS var int sw1_uS = pulseMin; // 3-way Switch 1 combines result from swPin_D1 and D2 int sw2_uS = pulseMin; // 2-way Switch 2 results from swPin_D3 void setup() { pinMode(potPin_A1, INPUT); //set potPin_A1 to be an input pinMode(potPin_A2, INPUT); //set potPin_A2 to be an input pinMode(swPin_D1, INPUT); //set swPin_D1 to be an input digitalWrite(swPin_D1, HIGH); // turn on pull-up resistor pinMode(swPin_D2, INPUT); //set swPin_D2 to be an input digitalWrite(swPin_D2, HIGH); // turn on pull-up resistor pinMode(swPin_D3, INPUT); //set swPin_D3 to be an input digitalWrite(swPin_D3, HIGH); // turn on pull-up resistor pinMode(outPinPPM, OUTPUT); //set ppmPin to be an OUTPUT digitalWrite(outPinPPM, HIGH);// turn on LED /* // Setup timer TCCR1A = B00110001; // Compare register B used in mode '3' TCCR1B = B00010010; // WGM13 and CS11 set to 1 TCCR1C = B00000000; // All set to 0 TIMSK1 = B00000010; // Interrupt on compare B TIFR1 = B00000010; // Interrupt on compare B OCR1A = 22000; // 22mS PPM output refresh OCR1B = 1000; */ //For Digispark use Timer0 TCCR0A = (1 << WGM01); //CTC mode TCCR0B = (2 << CS00); //div8 OCR0A = F_CPU/8 * 0.000050 - 1; //50ms -- need to change to 22us compare value TIMSK |= (1<= pulseMax) A1_uS = pulseMax; // Max if (A2_uS <= pulseMin) A2_uS = pulseMin; // Min if (A2_uS >= pulseMax) A2_uS = pulseMax; // Max */ if (digitalRead(swPin_D1) != 1) { // 3-way Switch 1 sw1_uS = pulseMin; } else { if (digitalRead(swPin_D2) != 1 ) { sw1_uS = pulseMax; } else { sw1_uS = pulseMid; } } if (digitalRead(swPin_D3) != 1) { // 2-way Switch 2 sw2_uS = pulseMin; } else { sw2_uS = pulseMax; } }