mirror of
				https://github.com/digistump/DigistumpArduino.git
				synced 2025-11-03 13:04:48 -08:00 
			
		
		
		
	Add OLED library - update tiny wire libraries - add support for all PWM channels and PWM on pin 8
This commit is contained in:
		@@ -19,6 +19,8 @@ SoftRcPulseOut myservo;  // create servo object to control a servo
 | 
			
		||||
 | 
			
		||||
#define REFRESH_PERIOD_MS 20
 | 
			
		||||
 | 
			
		||||
#define NOW               1
 | 
			
		||||
 | 
			
		||||
int val;    // variable to read the value from the analog pin 
 | 
			
		||||
 
 | 
			
		||||
void setup() 
 | 
			
		||||
@@ -32,6 +34,6 @@ void loop()
 | 
			
		||||
  val = map(val, 0, 1023, 0, 179);     // scale it to use it with the servo (value between 0 and 180) 
 | 
			
		||||
  myservo.write(val);                  // sets the servo position according to the scaled value 
 | 
			
		||||
  delay(REFRESH_PERIOD_MS);            // waits for the servo to get there 
 | 
			
		||||
  SoftRcPulseOut::refresh();            // generates the servo pulse
 | 
			
		||||
  SoftRcPulseOut::refresh(NOW);        // generates the servo pulse Now
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -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
 | 
			
		||||
 
 | 
			
		||||
@@ -12,6 +12,8 @@ SoftRcPulseOut myservo;  // create servo object to control a servo
 | 
			
		||||
 | 
			
		||||
#define REFRESH_PERIOD_MS 20
 | 
			
		||||
 | 
			
		||||
#define NOW               1
 | 
			
		||||
 | 
			
		||||
int pos = 0;    // variable to store the servo position 
 | 
			
		||||
 
 | 
			
		||||
void setup() 
 | 
			
		||||
@@ -26,12 +28,12 @@ void loop()
 | 
			
		||||
  {                                  // in steps of 1 degree 
 | 
			
		||||
    myservo.write(pos);              // tell servo to go to position in variable 'pos' 
 | 
			
		||||
    delay(REFRESH_PERIOD_MS);        // waits 20ms for refresh period 
 | 
			
		||||
    SoftRcPulseOut::refresh(1);        // generates the servo pulse
 | 
			
		||||
    SoftRcPulseOut::refresh(NOW);    // generates the servo pulse Now
 | 
			
		||||
  } 
 | 
			
		||||
  for(pos = 180; pos>=1; pos-=1)     // goes from 180 degrees to 0 degrees 
 | 
			
		||||
  {                                
 | 
			
		||||
    myservo.write(pos);              // tell servo to go to position in variable 'pos' 
 | 
			
		||||
    delay(REFRESH_PERIOD_MS);        // waits 20ms for for refresh period 
 | 
			
		||||
    SoftRcPulseOut::refresh(1);        // generates the servo pulse
 | 
			
		||||
    SoftRcPulseOut::refresh(NOW);    // generates the servo pulse Now
 | 
			
		||||
  } 
 | 
			
		||||
} 
 | 
			
		||||
 
 | 
			
		||||
@@ -0,0 +1,37 @@
 | 
			
		||||
// SweepNoDelay
 | 
			
		||||
// by RC Navy (http://p.loussouarn.free.fr/arduino/arduino.html>)
 | 
			
		||||
// This sketch can work with ATtiny and Arduino UNO, MEGA, etc...
 | 
			
		||||
// This example code is in the public domain.
 | 
			
		||||
 | 
			
		||||
#include <SoftRcPulseOut.h> 
 | 
			
		||||
 
 | 
			
		||||
SoftRcPulseOut myservo;  // create servo object to control a servo 
 | 
			
		||||
                        // a maximum of eight servo objects can be created 
 | 
			
		||||
#define SERVO_PIN         0
 | 
			
		||||
 | 
			
		||||
#define UP_DIRECTION      +1
 | 
			
		||||
#define DOWN_DIRECTION    -1
 | 
			
		||||
 | 
			
		||||
#define POS_MIN           0
 | 
			
		||||
#define POS_MAX           180
 | 
			
		||||
 | 
			
		||||
int pos = POS_MIN;    // variable to store the servo position 
 | 
			
		||||
int step = UP_DIRECTION;
 | 
			
		||||
 | 
			
		||||
void setup() 
 | 
			
		||||
{ 
 | 
			
		||||
  myservo.attach(SERVO_PIN);  // attaches the servo on pin defined by SERVO_PIN to the servo object 
 | 
			
		||||
  myservo.write(pos);
 | 
			
		||||
} 
 | 
			
		||||
 
 | 
			
		||||
void loop() 
 | 
			
		||||
{
 | 
			
		||||
  if (SoftRcPulseOut::refresh())    // refresh() returns 1 every 20ms (after pulse update)
 | 
			
		||||
  {
 | 
			
		||||
    // We arrive here every 20ms
 | 
			
		||||
    pos += step;
 | 
			
		||||
    if(pos >= POS_MAX) step = DOWN_DIRECTION; //180 degrees reached -> Change direction
 | 
			
		||||
    if(pos <= POS_MIN) step = UP_DIRECTION;   //  0 degrees reached -> Change direction
 | 
			
		||||
    myservo.write(pos);
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
@@ -19,6 +19,7 @@ SoftRcPulseOut myservo;  // create servo object to control a servo
 | 
			
		||||
 | 
			
		||||
#define REFRESH_PERIOD_MS 20
 | 
			
		||||
 | 
			
		||||
#define NOW               1
 | 
			
		||||
 | 
			
		||||
#define MOY_SUR_1_VALEUR        0
 | 
			
		||||
#define MOY_SUR_2_VALEURS       1
 | 
			
		||||
@@ -46,8 +47,8 @@ static int ValMoyennee;
 | 
			
		||||
  val = analogRead(POT_PIN);           // reads the value of the potentiometer (value between 0 and 1023) 
 | 
			
		||||
  val = map(val, 0, 1023, 0, 179);     // scale it to use it with the servo (value between 0 and 180) 
 | 
			
		||||
  MOYENNE(ValMoyennee,val,TAUX_DE_MOYENNAGE);//If there is lots of noise: average with TAUX_DE_MOYENNAGE
 | 
			
		||||
  myservo.write(ValMoyennee);                  // sets the servo position according to the scaled value 
 | 
			
		||||
  myservo.write(ValMoyennee);          // sets the servo position according to the scaled value 
 | 
			
		||||
  delay(REFRESH_PERIOD_MS);            // waits for the servo to get there 
 | 
			
		||||
  SoftRcPulseOut::refresh();            // generates the servo pulse
 | 
			
		||||
  SoftRcPulseOut::refresh(NOW);        // generates the servo pulse
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user