#include #include #define CH_MAX_NB 4 #define PPM_PERIOD_US 20000 // PPM Encoder Analog Add-ons for Devo7e // For use with Digispark // J. Diehl 12/13/2015 // Version 1.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-2 and -4 // 3-way (On-off-On) switch on JP3-0 and-3 // 2-way (On-off) switch on JP3-5 - Currently this is a reset // PPM output on JP3-1 // PPM inout to tip of 3.5 mono jack, this is the black wire on your Devo 7E DSC port int potPin_A1 = 1; //Declare potPin_A1 to be analog A1, pin p2 - no conflicts int pPdPin_A1 = 2; // use digital pin number p2 to set mode int potPin_A2 = 2; //Declare potPin_A2 to be analog A2, pin p4 - used in USB int pPdPin_A2 = 4; // use digital pin number p4 to set mode 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 p0 - no conflicts byte swPin_D2 = 3; //Declare swPin_D2 to be Digital pin pin p3 - used in USB byte swPin_D3 = 5; //Declare swPin_D3 to be Digital pin pin p5 - also NRESET int outPinPPM = 1; // Declare ppmPin to be pin pin p1; LED is on this line int Fixed_uS = 300; // PPM frame fixed LOW phase int pulseMin = 1000; // pulse minimum width minus start in uS int pulseMax = 2000; // pulse maximum width in uS int pulseMid = pulseMin + (pulseMax - pulseMin) / 2; 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(pPdPin_A1, INPUT); //set potPin_A1 to be an input pinMode(pPdPin_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 TinyPpmGen.begin(TINY_PPM_GEN_POS_MOD, CH_MAX_NB, PPM_PERIOD_US); /* Change TINY_PPM_GEN_POS_MOD to TINY_PPM_GEN_NEG_MOD for NEGative PPM modulation */ } void loop() { getChan(); TinyPpmGen.setChWidth_us(1, A1_uS); /* RC Channel#1 */ TinyPpmGen.setChWidth_us(2, A2_uS); /* RC Channel#2 */ TinyPpmGen.setChWidth_us(3, sw1_uS); /* RC Channel#3 */ TinyPpmGen.setChWidth_us(4, sw2_uS); /* RC Channel#4 */ } void getChan() { // logic to read each analog input // Read analog pins AI_Raw_A1 = analogRead(potPin_A1); // Analog Pot 1 AI_Raw_A2 = analogRead(potPin_A2); // Analog Pot 2 AI_Raw_A2 = 500; // testing // Map analog inputs to PPM rates for each of the channels // compensate for analog 0-1023 vs expected pulseMin-pulseMax A1_uS = map (AI_Raw_A1,0,1023,pulseMin,pulseMax); A2_uS = map (AI_Raw_A2,0,1023,pulseMin,pulseMax); 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; } } /* Currently this pin resets the Digispark * if (digitalRead(swPin_D3) != 1) { // 2-way Switch 2 sw2_uS = pulseMin; } else { sw2_uS = pulseMax; } */ }