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.
Revision 22:72357412608d, committed 2020-01-27
- Comitter:
- eencae
- Date:
- Mon Jan 27 13:58:59 2020 +0000
- Parent:
- 21:da0b4e14c867
- Child:
- 23:8e1a30a69caa
- Commit message:
- Added DAC access;
Changed in this revision
| Gamepad.cpp | Show annotated file Show diff for this revision Revisions of this file |
| Gamepad.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/Gamepad.cpp Mon Jan 27 12:31:15 2020 +0000
+++ b/Gamepad.cpp Mon Jan 27 13:58:59 2020 +0000
@@ -23,7 +23,7 @@
_pot1(new AnalogIn(PTB2)),
_pot2(new AnalogIn(PTB3)),
-
+
dac(new AnalogOut(DAC0_OUT)),
ticker(new Ticker),
timeout(new Timeout),
@@ -60,7 +60,7 @@
// initalise button flags
reset_buttons();
-
+
// number of samples
_n = 16;
_sample_array = new float[_n];
@@ -113,9 +113,9 @@
if (val > 1.0f) {
val = 1.0f;
}
-
+
switch (n) {
-
+
// check for valid LED number and set value
case 1:
@@ -196,11 +196,13 @@
return d;
}
-void Gamepad::reset_buttons() {
+void Gamepad::reset_buttons()
+{
A_fall = B_fall = X_fall = Y_fall = start_fall = false;
}
-bool Gamepad::A_pressed() {
+bool Gamepad::A_pressed()
+{
if (A_fall) {
A_fall = false;
return true;
@@ -209,7 +211,8 @@
}
}
-bool Gamepad::B_pressed() {
+bool Gamepad::B_pressed()
+{
if (B_fall) {
B_fall = false;
return true;
@@ -218,7 +221,8 @@
}
}
-bool Gamepad::X_pressed() {
+bool Gamepad::X_pressed()
+{
if (X_fall) {
X_fall = false;
return true;
@@ -227,7 +231,8 @@
}
}
-bool Gamepad::Y_pressed() {
+bool Gamepad::Y_pressed()
+{
if (Y_fall) {
Y_fall = false;
return true;
@@ -236,7 +241,8 @@
}
}
-bool Gamepad::start_pressed() {
+bool Gamepad::start_pressed()
+{
if (start_fall) {
start_fall = false;
return true;
@@ -245,24 +251,29 @@
}
}
-bool Gamepad::A_held() {
+bool Gamepad::A_held()
+{
// Buttons are configured as PullUp hence the not
return !_button_A->read();
}
-bool Gamepad::B_held() {
+bool Gamepad::B_held()
+{
return !_button_B->read();
}
-bool Gamepad::X_held() {
+bool Gamepad::X_held()
+{
return !_button_X->read();
}
-bool Gamepad::Y_held() {
+bool Gamepad::Y_held()
+{
return !_button_Y->read();
}
-bool Gamepad::start_held() {
+bool Gamepad::start_held()
+{
return !_button_start->read();
}
@@ -342,19 +353,24 @@
}
// ISRs for buttons
-void Gamepad::A_fall_interrupt() {
+void Gamepad::A_fall_interrupt()
+{
A_fall = true;
}
-void Gamepad::B_fall_interrupt() {
+void Gamepad::B_fall_interrupt()
+{
B_fall = true;
}
-void Gamepad::X_fall_interrupt() {
+void Gamepad::X_fall_interrupt()
+{
X_fall = true;
}
-void Gamepad::Y_fall_interrupt() {
+void Gamepad::Y_fall_interrupt()
+{
Y_fall = true;
}
-void Gamepad::start_fall_interrupt() {
+void Gamepad::start_fall_interrupt()
+{
start_fall = true;
}
@@ -392,6 +408,16 @@
play_next_note(); // play the next note in the melody
}
+void Gamepad::write_dac(float val)
+{
+ if (val < 0.0f) {
+ val = 0.0f;
+ } else if (val > 1.0f) {
+ val = 1.0f;
+ }
+ dac->write(val);
+}
+
void Gamepad::play_next_note()
{
--- a/Gamepad.h Mon Jan 27 12:31:15 2020 +0000
+++ b/Gamepad.h Mon Jan 27 13:58:59 2020 +0000
@@ -233,6 +233,9 @@
// change the BPM
void set_bpm(float bpm);
+
+ // write to DAC
+ void write_dac(float val);