Library for ELEC2645 Gamepad PCB. University of Leeds Version 2 January 2020
Dependents: ELEC2645_Ticker_WAV ELEC2645_Project_username ELEC2645_Project_el18vgt ELEC2645_Project_el17oc11 ... more
Diff: Gamepad.cpp
- Revision:
- 9:893189072e89
- Parent:
- 8:7eaf26f4b5f2
- Child:
- 10:a13d2f9d8a14
--- a/Gamepad.cpp Tue Feb 07 10:53:46 2017 +0000 +++ b/Gamepad.cpp Tue Feb 07 11:50:26 2017 +0000 @@ -1,23 +1,14 @@ -/** -@file Gamepad.cpp - -@brief member function implementations - -@author Dr Craig A. Evans - -*/ - #include "Gamepad.h" //////////// constructor/destructor //////////// Gamepad::Gamepad() { - led_1 = new PwmOut(PTA1); - led_2 = new PwmOut(PTA2); - led_3 = new PwmOut(PTC2); - led_4 = new PwmOut(PTC3); - led_5 = new PwmOut(PTC4); - led_6 = new PwmOut(PTD3); + led1 = new PwmOut(PTA1); + led2 = new PwmOut(PTA2); + led3 = new PwmOut(PTC2); + led4 = new PwmOut(PTC3); + led5 = new PwmOut(PTC4); + led6 = new PwmOut(PTD3); button_A = new InterruptIn(PTB9); button_B = new InterruptIn(PTD0); @@ -41,7 +32,7 @@ Gamepad::~Gamepad() { - delete led_1,led_2,led_3,led_4,led_5,led_6; + delete led1,led2,led3,led4,led5,led6; delete button_A,button_B,button_joystick,vert,horiz; delete button_X, button_Y, button_back, button_start; delete button_L, button_R, buzzer, pot, timeout; @@ -66,15 +57,15 @@ void Gamepad::leds_off() { - fade_leds(0.0); + set_leds(0.0); } void Gamepad::leds_on() { - fade_leds(1.0); + set_leds(1.0); } -void Gamepad::fade_leds(float val) +void Gamepad::set_leds(float val) { if (val < 0.0f) { val = 0.0f; @@ -87,12 +78,31 @@ // 0.0 corresponds to fully-off, 1.0 to fully-on val = 1.0f - val; - led_1->write(val); - led_2->write(val); - led_3->write(val); - led_4->write(val); - led_5->write(val); - led_6->write(val); + led1->write(val); + led2->write(val); + led3->write(val); + led4->write(val); + led5->write(val); + led6->write(val); +} + +void Gamepad::set_led1(float val) { + led1->write(1.0f-val); // active-low so subtract from 1 +} +void Gamepad::set_led2(float val) { + led2->write(1.0f-val); // active-low so subtract from 1 +} +void Gamepad::set_led3(float val) { + led3->write(1.0f-val); // active-low so subtract from 1 +} +void Gamepad::set_led4(float val) { + led4->write(1.0f-val); // active-low so subtract from 1 +} +void Gamepad::set_led5(float val) { + led5->write(1.0f-val); // active-low so subtract from 1 +} +void Gamepad::set_led6(float val) { + led6->write(1.0f-val); // active-low so subtract from 1 } float Gamepad::read_pot()