Add OLED library - update tiny wire libraries - add support for all PWM channels and PWM on pin 8

This commit is contained in:
Erik Tylek Kettenburg
2015-01-14 18:08:45 -08:00
parent fb93846380
commit 52f444d221
60 changed files with 3285 additions and 710 deletions

View File

@@ -0,0 +1,52 @@
SoftRcPulseIn library
======================
**SoftRcPulseIn** is an asynchronous library designed to read RC pulse signals. It is a non-blocking version of arduino **pulseIn()** function.
Some examples of use cases:
-------------------------
* **RC Servo/ESC/Brushless Controller**
* **Multi-switch (RC Channel to digital outputs converter)** (look at **RcSeq** library)
* **Servo sequencer** (look at **RcSeq** library which uses **SoftRcPulseOut** library)
* **RC Robot using wheels with modified Servo to support 360° rotation**
* **RC pulse stretcher** (in conjunction with **SoftRcPulseOut** library)
Supported Arduinos:
------------------
* **ATmega328 (UNO)**
* **ATmega2560 (MEGA)**
* **ATtiny84 (Standalone)**
* **ATtiny85 (Standalone or Digispark)**
* **ATtiny167 (Digispark pro)**
Tip and Tricks:
--------------
Develop your project on an arduino UNO or MEGA, and then shrink it by loading the sketch in an ATtiny or Digispark (pro).
API/methods:
-----------
* attach()
* available()
* width_us()
* timeout()
* LibVersion()
* LibRevision()
* LibTextVersionRevision()
Design considerations:
---------------------
The **SoftRcPulseIn** library relies the **TinyPinChange** library. This one shall be included in the sketch as well.
On the arduino MEGA, as all the pins do not support "pin change interrupt", only the following pins are supported:
* 10 -> 15
* 50 -> 53
* A8 -> A15
On other devices (ATmega328, ATtiny84, ATtiny85 and ATtiny167), all the pins are usable.
Contact
-------
If you have some ideas of enhancement, please contact me by clicking on: [RC Navy](http://p.loussouarn.free.fr/contact.html).

View File

@@ -1,19 +1,22 @@
/*
English: by RC Navy (2012)
English: by RC Navy (2012-2015)
=======
<SoftRcPulseIn>: an asynchronous library to read Input Pulse Width from standard Hobby Radio-Control. This library is a non-blocking version of pulseIn().
http://p.loussouarn.free.fr
Francais: par RC Navy (2012)
V1.0: initial release
V1.1: asynchronous timeout support added (up to 250ms)
Francais: par RC Navy (2012-2015)
========
<SoftRcPulseIn>: une librairie asynchrone pour lire les largeur d'impulsions des Radio-Commandes standards. Cette librairie est une version non bloquante de pulsIn().
http://p.loussouarn.free.fr
V1.0: release initiale
V1.1: support de timeout asynchrone ajoutee (jusqu'a 250ms)
*/
#include "SoftRcPulseIn.h"
#define LIB_VERSION 1
#define LIB_REVISION 0
#define LIB_VERSION 1
#define LIB_REVISION 1
#define STR(s) #s
#define MAKE_TEXT_VER_REV(Ver,Rev) STR(Ver)"."STR(Rev)
@@ -31,15 +34,15 @@ uint8_t SoftRcPulseIn::attach(uint8_t Pin, uint16_t PulseMin_us/*=600*/, uint16_
uint8_t Ret=0;
_Pin=Pin;
_PinMask=TinyPinChange_PinToMsk(Pin);
_Min_us=PulseMin_us;
_Max_us=PulseMax_us;
_PinMask = TinyPinChange_PinToMsk(Pin);
_Min_us = PulseMin_us;
_Max_us = PulseMax_us;
next = first;
first = this;
pinMode(_Pin,INPUT);
digitalWrite(_Pin, HIGH);
_VirtualPortIdx=TinyPinChange_RegisterIsr(_Pin,SoftRcPulseIn::SoftRcPulseInInterrupt);
if(_VirtualPortIdx>=0)
_VirtualPortIdx = TinyPinChange_RegisterIsr(_Pin, SoftRcPulseIn::SoftRcPulseInInterrupt);
if(_VirtualPortIdx >= 0)
{
TinyPinChange_EnablePin(_Pin);
Ret=1;
@@ -70,19 +73,32 @@ uint16_t PulseWidth_us;
if(_Available)
{
noInterrupts();
PulseWidth_us=_Width_us;
PulseWidth_us = _Width_us;
interrupts();
Ret=_Available && (PulseWidth_us>=_Min_us) && (PulseWidth_us<=_Max_us);
Ret=_Available && (PulseWidth_us >= _Min_us) && (PulseWidth_us <= _Max_us);
_Available=0;
}
return(Ret);
}
#ifdef SOFT_RC_PULSE_IN_TIMEOUT_SUPPORT
boolean SoftRcPulseIn::timeout(uint8_t TimeoutMs, uint8_t *CurrentState)
{
uint8_t CurMs, Ret = 0;
CurMs = (uint8_t)(millis() & 0x000000FF);
if((uint8_t)(CurMs - _LastTimeStampMs) >= TimeoutMs)
{
*CurrentState = digitalRead(_Pin);
Ret = 1;
}
return(Ret);
}
#endif
uint16_t SoftRcPulseIn::width_us(void)
{
uint16_t PulseWidth_us;
noInterrupts();
PulseWidth_us=_Width_us;
PulseWidth_us = _Width_us;
interrupts();
return(PulseWidth_us);
}
@@ -98,13 +114,16 @@ SoftRcPulseIn *RcPulseIn;
if(digitalRead(RcPulseIn->_Pin))
{
/* High level, rising edge: start chrono */
RcPulseIn->_Start_us=micros();
RcPulseIn->_Start_us = micros();
}
else
{
/* Low level, falling edge: stop chrono */
RcPulseIn->_Width_us=micros()-RcPulseIn->_Start_us;
RcPulseIn->_Available=1;
RcPulseIn->_Width_us = micros() - RcPulseIn->_Start_us;
RcPulseIn->_Available = 1;
#ifdef SOFT_RC_PULSE_IN_TIMEOUT_SUPPORT
RcPulseIn->_LastTimeStampMs = (uint8_t)(millis() & 0x000000FF);
#endif
}
}
}

View File

@@ -1,10 +1,10 @@
/*
English: by RC Navy (2012)
English: by RC Navy (2012-2015)
=======
<SoftRcPulseIn>: an asynchronous library to read Input Pulse Width from standard Hobby Radio-Control. This library is a non-blocking version of pulseIn().
http://p.loussouarn.free.fr
Francais: par RC Navy (2012)
Francais: par RC Navy (2012-2015)
========
<SoftRcPulseIn>: une librairie asynchrone pour lire les largeur d'impulsions des Radio-Commandes standards. Cette librairie est une version non bloquante de pulsIn().
http://p.loussouarn.free.fr
@@ -23,6 +23,8 @@
#include <inttypes.h>
#define SOFT_RC_PULSE_IN_TIMEOUT_SUPPORT
class SoftRcPulseIn
{
public:
@@ -31,8 +33,9 @@ class SoftRcPulseIn
static int LibRevision(void);
static char *LibTextVersionRevision(void);
static void SoftRcPulseInInterrupt(void);
uint8_t attach(uint8_t Pin, uint16_t PulseMin_us=600, uint16_t PulseMax_us=2400);
uint8_t attach(uint8_t Pin, uint16_t PulseMin_us = 600, uint16_t PulseMax_us = 2400);
boolean available();
boolean timeout(uint8_t TimeoutMs, uint8_t *State);
uint16_t width_us();
private:
class SoftRcPulseIn *next;
@@ -45,6 +48,9 @@ class SoftRcPulseIn
uint32_t _Start_us;
uint32_t _Width_us;
boolean _Available;
#ifdef SOFT_RC_PULSE_IN_TIMEOUT_SUPPORT
uint8_t _LastTimeStampMs;
#endif
};
/*******************************************************/
/* Application Programming Interface (API) en Francais */

View File

@@ -52,6 +52,8 @@
#define RX_AUX_GEAR_PIN 0 //Choose here the pin for the RC signal
#define DEBUG_TX_RX_PIN 1 //Adjust here your Tx/Rx debug pin (Do NOT work on Digispark PIN 5: choose another PIN)
#define SERIAL_BAUD_RATE 57600 //Adjust rate here
SoftRcPulseIn RxAuxGear; //Choose a name for your RC channel signal
SoftSerial MyDbgSerial(DEBUG_TX_RX_PIN, DEBUG_TX_RX_PIN, true); //true allows to connect to a regular RS232 without RS232 line driver
@@ -60,7 +62,7 @@ void setup()
{
RxAuxGear.attach(RX_AUX_GEAR_PIN);
MyDbgSerial.begin(38400); //Do NOT forget to setup your terminal at 38400 (eg: arduino IDE serial monitor)
MyDbgSerial.begin(SERIAL_BAUD_RATE); //Do NOT forget to setup your terminal at same baud rate (eg: arduino IDE serial monitor)
MyDbgSerial.txMode(); //Before sending a message, switch to txMode
MyDbgSerial.print(F("SoftRcPulseIn lib V"));MyDbgSerial.print(SoftRcPulseIn::LibTextVersionRevision());MyDbgSerial.println(F(" demo"));
}

View File

@@ -52,7 +52,7 @@ boolean LedState=HIGH;
void setup()
{
#if !defined(__AVR_ATtiny24__) && !defined(__AVR_ATtiny44__) && !defined(__AVR_ATtiny84__) && !defined(__AVR_ATtiny25__) && !defined(__AVR_ATtiny45__) && !defined(__AVR_ATtiny85__)
#if !defined(__AVR_ATtiny24__) && !defined(__AVR_ATtiny44__) && !defined(__AVR_ATtiny84__) && !defined(__AVR_ATtiny25__) && !defined(__AVR_ATtiny45__) && !defined(__AVR_ATtiny85__) && !defined(__AVR_ATtiny167__)
Serial.begin(9600);
Serial.print("SoftRcPulseIn library V");Serial.print(SoftRcPulseIn::LibTextVersionRevision());Serial.print(" demo"); /* For arduino UNO which has an hardware UART, display the library version in the console */
#endif
@@ -74,8 +74,8 @@ static uint16_t Width_us=NEUTRAL_US; /* Static to keep the value at the next loo
ServoMotor[INVERTED].write_us((NEUTRAL_US*2)-Width_us); /* Inverted Signal */
SoftRcPulseOut::refresh(NOW); /* NOW argument (=1) allows to synchronize outgoing pulses with incoming pulses */
RxPulseStartMs=millis(); /* Restart the Chrono for Pulse */
#if !defined(__AVR_ATtiny24__) && !defined(__AVR_ATtiny44__) && !defined(__AVR_ATtiny84__) && !defined(__AVR_ATtiny25__) && !defined(__AVR_ATtiny45__) && !defined(__AVR_ATtiny85__)
Serial.print("Pulse=");Serial.println(Largeur_us); /* For arduino UNO which has an hardware UART, display the library version in the console */
#if !defined(__AVR_ATtiny24__) && !defined(__AVR_ATtiny44__) && !defined(__AVR_ATtiny84__) && !defined(__AVR_ATtiny25__) && !defined(__AVR_ATtiny45__) && !defined(__AVR_ATtiny85__) && !defined(__AVR_ATtiny167__)
Serial.print("Pulse=");Serial.println(Width_us); /* For arduino UNO which has an hardware UART, display the library version in the console */
#endif
}
else

View File

@@ -18,6 +18,7 @@ attach KEYWORD2
attache KEYWORD2
available KEYWORD2
disponible KEYWORD2
timeout KEYWORD2
width_us KEYWORD2
largeur_us KEYWORD2