X-Git-Url: http://git.piffa.net/web?a=blobdiff_plain;f=esempi%2Fsnippets%2Flettura_servo_ch_pulse%2Flettura_servo_ch_pulse.ino;fp=esempi%2Fsnippets%2Flettura_servo_ch_pulse%2Flettura_servo_ch_pulse.ino;h=f138c84ce7db7ef089db54da639714035db56dbd;hb=4f1a2108ba34533e92d1aa7e84328ea36df08f22;hp=0000000000000000000000000000000000000000;hpb=bcaafb8d3e90a958629f767fc5b276fc9789bb96;p=aerei diff --git a/esempi/snippets/lettura_servo_ch_pulse/lettura_servo_ch_pulse.ino b/esempi/snippets/lettura_servo_ch_pulse/lettura_servo_ch_pulse.ino new file mode 100644 index 0000000..f138c84 --- /dev/null +++ b/esempi/snippets/lettura_servo_ch_pulse/lettura_servo_ch_pulse.ino @@ -0,0 +1,45 @@ + +/* Lettura di un canale servo della RX + + Lettura tramite la finzione pulsein + Utilizzabile su qualunque PIN + +*/ + +#include + +unsigned long currentMillis; // timestamp reference per millis per tutto il loop + +// Variabili +const byte chPin = A4; // PIN su cui e' collegato il canale +long unsigned chStamp = 0; // Timestamp per +unsigned int chIn = 1500; // Valore catturato +unsigned int chValue = 1500; // Valore computato +unsigned int freq = 200 ; // Ogni quanti millisecondi leggere il valore +// Attenzione che pulsein e' blocking + +void setup() { + // Funzione relativa a calibrazione: +// mid_point = calibraTrim(chPin) ; // + LED di servizio per monitor calibrazione +} ; + +void loop() { + currentMillis = millis(); // Timestamp per tutto il loop + +// Lettura ailerons channel ogni 200ms + if (currentMillis - chStamp >= freq) { + chStamp = currentMillis ; + + chIn = pulseIn(chPin, HIGH, 25000); + if (chIn != 0 && chIn > 1000 && chIn <2000) { + // get only resonable values + chValue = chIn; + } ; +// Lettura Aileron channel: FAKE con un potenziometro 10K +// chIn = analogRead(chPin); +// chValue = 1000 + chIn + }; + + +// do something with chValue +}