APM:Libraries
ToshibaLED_test.cpp
Go to the documentation of this file.
1 #include <AP_HAL/AP_HAL.h>
2 #include <AP_Notify/AP_Notify.h>
4 
5 void setup();
6 void loop();
7 void full_spectrum();
8 void blink();
9 
11 
12 static ToshibaLED_I2C toshiba_led(1);
13 
14 void setup(void)
15 {
16  // display welcome message
17  hal.console->printf("Toshiba LED test ver 0.1\n");
18 
19  // initialise LED
20  toshiba_led.init();
21 
22  // check if healthy
23  if (!toshiba_led.healthy()) {
24  hal.console->printf("Failed to initialise Toshiba LED\n");
25  }
26 
27  // turn on initialising notification
33 }
34 
35 void loop(void)
36 {
37  // blink test
38  //hal.console->printf("Blink test\n");
39  //blink();
40  /*
41  // full spectrum test
42  hal.console->printf("Spectrum test\n");
43  full_spectrum();
44  */
45 
46  // update the toshiba led
48 
49  // wait 1/50th of a second
50  hal.scheduler->delay(20);
51 }
52 
53 // full_spectrum - runs through the full spectrum of colours the led can display
55 {
56  // go through the full range of colours but only up to the dim light level
57  for (uint8_t red = 0; red <= 0x05; red++) {
58  for (uint8_t green = 0; green <= 0x05; green++) {
59  for (uint8_t blue = 0; blue <= 0x05; blue++) {
60  toshiba_led.set_rgb(red, green, blue);
61  hal.scheduler->delay(5);
62  }
63  }
64  }
65 }
66 
67 #define LED_DIM 0x11
68 
69 // blink - blink the led at 10hz for 10 seconds
70 void blink()
71 {
72  // set colour to red
74 
75  // full spectrum test
76  for (uint8_t c=0; c<=2; c++ ) {
77  if (c == 0) {
78  toshiba_led.set_rgb(LED_DIM, 0, 0); // red
79  }else if (c==1) {
80  toshiba_led.set_rgb(0, LED_DIM, 0); // green
81  }else{
82  toshiba_led.set_rgb(0, 0, LED_DIM); // blue
83  }
84  }
85 }
86 
87 AP_HAL_MAIN();
virtual void set_rgb(uint8_t red, uint8_t green, uint8_t blue)
Definition: RGBLed.cpp:66
void blink()
const AP_HAL::HAL & hal
-*- tab-width: 4; Mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*-
AP_HAL::UARTDriver * console
Definition: HAL.h:110
void full_spectrum()
static ToshibaLED_I2C toshiba_led(1)
#define LED_DIM
virtual void delay(uint16_t ms)=0
virtual void printf(const char *,...) FMT_PRINTF(2
Definition: BetterStream.cpp:5
void loop()
virtual bool init(void)
Definition: RGBLed.cpp:44
virtual bool healthy()
Definition: RGBLed.h:33
AP_HAL_MAIN()
const HAL & get_HAL()
void setup()
static struct notify_flags_and_values_type flags
Definition: AP_Notify.h:117
virtual void update()
Definition: RGBLed.cpp:339
AP_HAL::Scheduler * scheduler
Definition: HAL.h:114