Permalink
Browse files

add configurable LED flasher

This change uses PB4 (Arduino pin 12) to flash an LED. The sequence of
flashes is configurable by defining LED_FLASHER_SEQUENCE and can be
changed anytime; it is repeated every second.

This patch also introduces the define DISABLE_POWER_PIN, which instructs
Multiwii to not use PB4 for powering or resetting the WMP.
  • Loading branch information...
wertarbyte committed Mar 31, 2012
1 parent d5f97d1 commit 3eba548b1ebc8bac9bf9b9af148464a1bb4c9f24
Showing with 55 additions and 4 deletions.
  1. +24 −0 MultiWii/LED.pde
  2. +8 −0 MultiWii/MultiWii.ino
  3. +11 −0 MultiWii/config.h
  4. +12 −4 MultiWii/def.h
View
@@ -46,4 +46,28 @@ void blinkLedRing() {
i2c_stop();
}
+#endif
+
+#if defined(LED_FLASHER)
+
+static uint8_t led_flasher_sequence = 0;
+
+void init_led_flasher() {
+ LED_FLASHER_DDR |= (1<<LED_FLASHER_BIT);
+ LED_FLASHER_PORT &= ~(1<<LED_FLASHER_BIT);
+}
+
+void led_flasher_set_sequence(uint8_t s) {
+ led_flasher_sequence = s;
+}
+
+void switch_led_flasher() {
+ uint8_t seg = (currentTime/1000/125)%8;
+ if (led_flasher_sequence & 1<<seg) {
+ LED_FLASHER_PORT |= (1<<LED_FLASHER_BIT);
+ } else {
+ LED_FLASHER_PORT &= ~(1<<LED_FLASHER_BIT);
+ }
+}
+
#endif
View
@@ -306,6 +306,10 @@ void annexCode() { // this code is excetuted at each loop and won't interfere wi
}
#endif
+ #if defined(LED_FLASHER)
+ switch_led_flasher();
+ #endif
+
if ( currentTime > calibratedAccTime ) {
if (smallAngle25 == 0) {
calibratedACC = 0; // the multi uses ACC and is not calibrated or is too much inclinated
@@ -383,6 +387,10 @@ void setup() {
configurationLoop();
#endif
ADCSRA |= _BV(ADPS2) ; ADCSRA &= ~_BV(ADPS1); ADCSRA &= ~_BV(ADPS0); // this speeds up analogRead without loosing too much resolution: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1208715493/11
+ #if defined(LED_FLASHER)
+ init_led_flasher();
+ led_flasher_set_sequence(LED_FLASHER_SEQUENCE);
+ #endif
}
// ******** Main Loop *********
View
@@ -41,6 +41,14 @@
/* I2C DFRobot LED RING communication */
//#define LED_RING
+/* LED FLASHER */
+//#define LED_FLASHER
+//#define LED_FLASHER_DDR DDRB
+//#define LED_FLASHER_PORT PORTB
+//#define LED_FLASHER_BIT PB4
+// create double flashes
+//#define LED_FLASHER_SEQUENCE ( (uint8_t) (1<<0 | 1<<2) )
+
/* This option should be uncommented if ACC Z is accurate enough when motors are running*/
/* should now be ok with BMA020 and BMA180 ACC */
#define TRUSTED_ACCZ
@@ -60,6 +68,9 @@
//#define RCAUXPIN8
//#define RCAUXPIN12
+/* disable use of the POWER PIN */
+//#define DISABLE_POWER_PIN
+
/* GPS using a SERIAL port
only available on MEGA boards (this might be possible on 328 based boards in the future)
if enabled, define here the Arduino Serial port number and the UART speed
View
@@ -23,14 +23,16 @@
#define BUZZERPIN_OFF ;
#define RCAUXPIN
#endif
- #if !defined(RCAUXPIN12)
+ #if !defined(RCAUXPIN12) && !defined(DISABLE_POWER_PIN)
#define POWERPIN_PINMODE pinMode (12, OUTPUT);
#define POWERPIN_ON PORTB |= 1<<4;
#define POWERPIN_OFF PORTB &= ~(1<<4); //switch OFF WMP, digital PIN 12
#else
#define POWERPIN_PINMODE ;
#define POWERPIN_ON ;
#define POWERPIN_OFF ;
+ #endif
+ #if defined(RCAUXPIN12)
#define RCAUXPIN
#endif
#define I2C_PULLUPS_ENABLE PORTC |= 1<<4; PORTC |= 1<<5; // PIN A4&A5 (SDA&SCL)
@@ -202,9 +204,15 @@
#define BUZZERPIN_PINMODE pinMode (32, OUTPUT);
#define BUZZERPIN_ON PORTC |= 1<<5;
#define BUZZERPIN_OFF PORTC &= ~(1<<5);
- #define POWERPIN_PINMODE pinMode (37, OUTPUT);
- #define POWERPIN_ON PORTC |= 1<<0;
- #define POWERPIN_OFF PORTC &= ~(1<<0);
+ #if !defined(DISABLE_POWER_PIN)
+ #define POWERPIN_PINMODE pinMode (37, OUTPUT);
+ #define POWERPIN_ON PORTC |= 1<<0;
+ #define POWERPIN_OFF PORTC &= ~(1<<0);
+ #else
+ #define POWERPIN_PINMODE ;
+ #define POWERPIN_ON ;
+ #define POWERPIN_OFF ;
+ #endif
#define I2C_PULLUPS_ENABLE PORTD |= 1<<0; PORTD |= 1<<1; // PIN 20&21 (SDA&SCL)
#define I2C_PULLUPS_DISABLE PORTD &= ~(1<<0); PORTD &= ~(1<<1);
#define PINMODE_LCD pinMode(0, OUTPUT);

0 comments on commit 3eba548

Please sign in to comment.