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: Joystick.h
- Revision:
- 4:9553952c95f5
- Parent:
- 3:82731de4e878
- Child:
- 5:36cca0038ae3
--- a/Joystick.h Sun Jun 07 16:55:47 2020 +0000
+++ b/Joystick.h Sun Jun 07 17:07:22 2020 +0000
@@ -21,32 +21,44 @@
#include "mbed.h"
#include "Joystick.h"
-
+//I use STM32Nucleo L476 RG
// Xaxis,Yaxis,Button
Joystick joystick(PTB3, PTB2, PTB11);
DigitalOut r_led(LED_RED);
Serial pc(USBTX, USBRX);
+#include "Joystick.h"
+//Led1 switching task
+//I tired, so no fixation for button click
+Thread thread1;
+const int PWMPERIODMS = 20; //0,02s
+Joystick joy(PA_4,PB_0,PC_1);
+Serial pc(USBTX, USBRX);
+DigitalOut Led1(PB_10);
+PwmOut Led2(PB_4);
+PwmOut Led3(PB_3);
+void ledToggler()
+{
+ while(1) {
+ int button = joy.get_button_flag();
+ //Switching Led
+ if (button == 0) Led1 = 1;
+ else Led1 = 0;
+ }
+}
int main()
{
- //First initalise joystick
- joystick.init();
-
- while (true) {
- //Stores x and y output values
- float x, y;
-
- //Calls the "GetXValue" and "GetYValue" and stores it in x and y
- x = joystick.GetXValue();
- y = joystick.GetYValue();
-
- //Prints the values to the terminal
+ Led2.period_ms(PWMPERIODMS);
+ Led3.period_ms(PWMPERIODMS);
+ joy.init();
+ thread1.start(ledToggler);
+ while(1) {
+ float x = joy.GetXValue();
+ float y = joy.GetYValue();
pc.printf("X: %f, Y: %f\n", x, y);
-
- //If the button flag is pressed switch the led
- if (joystick.get_button_flag()) {
- r_led = !r_led
- }
+ //in Mbed OS PWM uses analogue values
+ Led2 = x;
+ Led3 = y;
}
}
* @endcode