Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: Gamepad.cpp
- Revision:
- 17:cf1e1ffcf773
- Parent:
- 16:3ea3d9714b0c
- Child:
- 18:e0a4f15a7750
--- a/Gamepad.cpp Fri Mar 03 13:19:19 2017 +0000
+++ b/Gamepad.cpp Sun Mar 05 19:01:31 2017 +0000
@@ -11,7 +11,7 @@
_led4(new PwmOut(PTC3)),
_led5(new PwmOut(PTC4)),
_led6(new PwmOut(PTD3)),
-
+
_button_A(new InterruptIn(PTB9)),
_button_B(new InterruptIn(PTD0)),
_button_X(new InterruptIn(PTC17)),
@@ -21,17 +21,17 @@
_button_back(new InterruptIn(PTB19)),
_button_start(new InterruptIn(PTC5)),
_button_joystick(new InterruptIn(PTC16)),
-
+
_vert(new AnalogIn(PTB10)),
_horiz(new AnalogIn(PTB11)),
-
+
_buzzer(new PwmOut(PTC10)),
_pot(new AnalogIn(PTB2)),
-
+
_timeout(new Timeout()),
-
+
_event_state(0),
-
+
_x0(0),
_y0(0)
{}
@@ -90,29 +90,32 @@
_led6->write(val);
}
-void Gamepad::led1(float val)
-{
- _led1->write(1.0f-val); // active-low so subtract from 1
-}
-void Gamepad::led2(float val)
-{
- _led2->write(1.0f-val); // active-low so subtract from 1
-}
-void Gamepad::led3(float val)
+void Gamepad::led(int n,float val)
{
- _led3->write(1.0f-val); // active-low so subtract from 1
-}
-void Gamepad::led4(float val)
-{
- _led4->write(1.0f-val); // active-low so subtract from 1
-}
-void Gamepad::led5(float val)
-{
- _led5->write(1.0f-val); // active-low so subtract from 1
-}
-void Gamepad::led6(float val)
-{
- _led6->write(1.0f-val); // active-low so subtract from 1
+ switch (n) {
+
+ // check for valid LED number and set value
+
+ case 1:
+ _led1->write(1.0f-val); // active-low so subtract from 1
+ break;
+ case 2:
+ _led2->write(1.0f-val); // active-low so subtract from 1
+ break;
+ case 3:
+ _led3->write(1.0f-val); // active-low so subtract from 1
+ break;
+ case 4:
+ _led4->write(1.0f-val); // active-low so subtract from 1
+ break;
+ case 5:
+ _led5->write(1.0f-val); // active-low so subtract from 1
+ break;
+ case 6:
+ _led6->write(1.0f-val); // active-low so subtract from 1
+ break;
+
+ }
}
float Gamepad::read_pot() const
@@ -187,6 +190,7 @@
void Gamepad::tone_off()
{
+ // called after timeout
_buzzer->write(0.0);
}