Practical Robotics Modular Robot Library

Dependents:   ModularRobot

Committer:
jah128
Date:
Fri Jan 13 23:16:23 2017 +0000
Revision:
6:732aa91eb555
Parent:
4:c2e933d53bea
Updated;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jah128 0:8a2dd255c508 1 #ifndef LED_H
jah128 0:8a2dd255c508 2 #define LED_H
jah128 0:8a2dd255c508 3
jah128 1:a6728adaf7e7 4 /**
jah128 1:a6728adaf7e7 5 * The Led class contains the functions to control the robots LEDs
jah128 1:a6728adaf7e7 6 */
jah128 0:8a2dd255c508 7 class Led
jah128 0:8a2dd255c508 8 {
jah128 0:8a2dd255c508 9 public:
jah128 0:8a2dd255c508 10
jah128 0:8a2dd255c508 11 /**
jah128 0:8a2dd255c508 12 * Sends the reset command to the reserved i2c address for the TLC59116 LED driver
jah128 0:8a2dd255c508 13 *
jah128 0:8a2dd255c508 14 * As the led driver is powered independently from the MBED, and the MBED can be reset externally, this reset operation should
jah128 0:8a2dd255c508 15 * be run as part of the initialisation routine to switch off the LEDs and restore them to the initial state.
jah128 0:8a2dd255c508 16 *
jah128 0:8a2dd255c508 17 * @return A zero if acknowledge recceived from LED driver chip, otherwise a non-zero
jah128 0:8a2dd255c508 18 */
jah128 0:8a2dd255c508 19 int reset_led_driver(void);
jah128 0:8a2dd255c508 20
jah128 0:8a2dd255c508 21 /**
jah128 0:8a2dd255c508 22 * Turns on the oscillator and enables all the LED outputs on the TLC59116 LED driver
jah128 0:8a2dd255c508 23 *
jah128 0:8a2dd255c508 24 *
jah128 0:8a2dd255c508 25 * @return A zero if acknowledge recceived from LED driver chip, otherwise a non-zero
jah128 0:8a2dd255c508 26 */
jah128 0:8a2dd255c508 27 int init_led_driver(void);
jah128 0:8a2dd255c508 28
jah128 4:c2e933d53bea 29 /**
jah128 4:c2e933d53bea 30 * Restores the currently stored states for the LEDs; used at the end of animation routines
jah128 4:c2e933d53bea 31 * to return the LED states to as they were. Also used when set_green_led_stored_state and
jah128 4:c2e933d53bea 32 * set_red_led_stored_state as called.
jah128 4:c2e933d53bea 33 */
jah128 4:c2e933d53bea 34 void restore_states(void);
jah128 4:c2e933d53bea 35
jah128 4:c2e933d53bea 36 /**
jah128 4:c2e933d53bea 37 * Set the brightness of all 8 LEDs to the same red, green brightness values
jah128 4:c2e933d53bea 38 *
jah128 4:c2e933d53bea 39 * @param red_brightness - The PWM duty cycle from 0 to 255 for the red LEDs
jah128 4:c2e933d53bea 40 * @param green_brightness - The PWM duty cycle from 0 to 255 for the green LEDs
jah128 4:c2e933d53bea 41 */
jah128 4:c2e933d53bea 42 void set_all (char red_brightness, char green_brightness);
jah128 4:c2e933d53bea 43
jah128 4:c2e933d53bea 44 /**
jah128 4:c2e933d53bea 45 * Set the brightness of all 8 LEDs to the same red, green brightness values
jah128 4:c2e933d53bea 46 *
jah128 4:c2e933d53bea 47 * @param * red_brightness - Pointer to an 8-char array for the PWM duty cycle from 0 to 255 for the red LEDs
jah128 4:c2e933d53bea 48 * @param * green_brightness - Pointer to an 8-char array for the PWM duty cycle from 0 to 255 for the green LEDs
jah128 4:c2e933d53bea 49 */
jah128 4:c2e933d53bea 50 void set_leds (char red1, char red2, char red3, char red4, char red5, char red6, char red7, char red8, char grn1, char grn2, char grn3, char grn4, char grn5, char grn6, char grn7, char grn8);
jah128 4:c2e933d53bea 51 void set_leds (char * red_brightness, char * green_brightness);
jah128 4:c2e933d53bea 52
jah128 0:8a2dd255c508 53 /**
jah128 3:8762f6b2ea8d 54 * Set the brightness of all case LEDs to zero
jah128 3:8762f6b2ea8d 55 */
jah128 3:8762f6b2ea8d 56 void all_off(void);
jah128 3:8762f6b2ea8d 57
jah128 3:8762f6b2ea8d 58 /**
jah128 4:c2e933d53bea 59 * Set an individual green led to the brightness specified; this function updates the
jah128 4:c2e933d53bea 60 * stored state for an individual LED and sets an I2C command to update the LED level
jah128 0:8a2dd255c508 61 *
jah128 4:c2e933d53bea 62 * Consider using set_X_led_stored_state and restore_states when many changes are to
jah128 4:c2e933d53bea 63 * be made at once to reduce number of i2c messages.
jah128 0:8a2dd255c508 64 *
jah128 4:c2e933d53bea 65 * @param led - The index of the LED from 0 to 7 (corresponds the 1 to 8 on the PCB)
jah128 4:c2e933d53bea 66 * @param brightness - The PWM duty cycle from 0 to 255
jah128 0:8a2dd255c508 67 */
jah128 0:8a2dd255c508 68 void set_green_led (char led, char brightness);
jah128 0:8a2dd255c508 69
jah128 0:8a2dd255c508 70 /**
jah128 4:c2e933d53bea 71 * Set an individual red led to the brightness specified; this function updates the
jah128 4:c2e933d53bea 72 * stored state for an individual LED and sets an I2C command to update the LED level
jah128 0:8a2dd255c508 73 *
jah128 4:c2e933d53bea 74 * Consider using set_X_led_stored_state and restore_states when many changes are to
jah128 4:c2e933d53bea 75 * be made at once to reduce number of i2c messages.
jah128 0:8a2dd255c508 76 *
jah128 4:c2e933d53bea 77 * @param led - The index of the LED from 0 to 7 (corresponds the 1 to 8 on the PCB)
jah128 4:c2e933d53bea 78 * @param brightness - The PWM duty cycle from 0 to 255
jah128 0:8a2dd255c508 79 */
jah128 0:8a2dd255c508 80 void set_red_led (char led, char brightness);
jah128 3:8762f6b2ea8d 81
jah128 3:8762f6b2ea8d 82 /**
jah128 4:c2e933d53bea 83 * Sets the stored brightness value for an individual green led without sending
jah128 4:c2e933d53bea 84 * actual i2c command; use restore_states to flush changes.
jah128 4:c2e933d53bea 85 *
jah128 4:c2e933d53bea 86 * @param led - The index of the LED from 0 to 7 (corresponds the 1 to 8 on the PCB)
jah128 4:c2e933d53bea 87 * @param brightness - The PWM duty cycle from 0 to 255
jah128 4:c2e933d53bea 88 */
jah128 4:c2e933d53bea 89 void set_green_led_stored_state (char led, char brightness);
jah128 4:c2e933d53bea 90
jah128 4:c2e933d53bea 91 /**
jah128 4:c2e933d53bea 92 * Sets the stored brightness value for an individual red led without sending
jah128 4:c2e933d53bea 93 * actual i2c command; use restore_states to flush changes.
jah128 4:c2e933d53bea 94 *
jah128 4:c2e933d53bea 95 * @param led - The index of the LED from 0 to 7 (corresponds the 1 to 8 on the PCB)
jah128 4:c2e933d53bea 96 * @param brightness - The PWM duty cycle from 0 to 255
jah128 4:c2e933d53bea 97 */
jah128 4:c2e933d53bea 98 void set_red_led_stored_state (char led, char brightness);
jah128 4:c2e933d53bea 99
jah128 0:8a2dd255c508 100
jah128 0:8a2dd255c508 101 /**
jah128 4:c2e933d53bea 102 * Stops the ticker-based routine
jah128 4:c2e933d53bea 103 */
jah128 4:c2e933d53bea 104 void stop_animation(void);
jah128 4:c2e933d53bea 105
jah128 4:c2e933d53bea 106 /**
jah128 4:c2e933d53bea 107 * Starts a ticker based LED animation
jah128 0:8a2dd255c508 108 *
jah128 0:8a2dd255c508 109 */
jah128 4:c2e933d53bea 110 void start_animation(char mode, char speed);
jah128 4:c2e933d53bea 111
jah128 4:c2e933d53bea 112 private:
jah128 4:c2e933d53bea 113
jah128 4:c2e933d53bea 114 void animation_cycle();
jah128 4:c2e933d53bea 115
jah128 4:c2e933d53bea 116 // The following do not stored`
jah128 4:c2e933d53bea 117 void _set_green_led (char led, char brightness);
jah128 4:c2e933d53bea 118 void _set_red_led (char led, char brightness);
jah128 4:c2e933d53bea 119 void _set_all (char red_brightness, char green_brightness);
jah128 4:c2e933d53bea 120 void _set_leds (char * red_brightness, char * green_brightness);
jah128 4:c2e933d53bea 121 void _set_leds (char red1, char red2, char red3, char red4, char red5, char red6, char red7, char red8, char grn1, char grn2, char grn3, char grn4, char grn5, char grn6, char grn7, char grn8);
jah128 4:c2e933d53bea 122
jah128 0:8a2dd255c508 123
jah128 0:8a2dd255c508 124 };
jah128 0:8a2dd255c508 125
jah128 0:8a2dd255c508 126 #endif