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.
Dependencies: mbed
Diff: main.cpp
- Revision:
- 0:86bb99faa77e
diff -r 000000000000 -r 86bb99faa77e main.cpp
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp Thu Oct 31 06:18:36 2019 +0000
@@ -0,0 +1,61 @@
+#include "mbed.h"
+#define speed 0.375
+#include "mbed.h"
+
+SPISlave spi(PA_7,PA_6,PA_5,PA_4);
+
+PwmOut motorUP(PA_10);
+PwmOut motorDOWN(PA_9);
+PwmOut motorLEFT(PA_8);
+PwmOut motorRIGHT(PA_1);
+
+void setting(void)
+{
+ motorUP.period_ms(1);
+ motorDOWN.period_ms(1);
+ motorLEFT.period_ms(1);
+ motorRIGHT.period_ms(1);
+ spi.format(8,3);
+ spi.frequency(1000000);
+}
+int main() {
+ motorRIGHT = 0;
+ motorLEFT = 0;
+ motorDOWN = 0;
+ motorUP = 0;
+ while(1) {
+ if (spi.read() == 128) { //ARM_UP
+ motorRIGHT = 0;
+ motorLEFT = 0;
+ motorDOWN = 0;
+ motorUP = 0.2;
+ printf("up/n");
+ }else if (spi.read() == 1) { //ARM_DOWN
+ motorRIGHT = 0;
+ motorLEFT = 0;
+ motorDOWN = 0.2;
+ motorUP = 0;
+ printf("down/n");
+ }else if (spi.read() == 129) { //LEFT
+ motorRIGHT = 0;
+ motorLEFT = speed;
+ motorDOWN = 0;
+ motorUP = 0;
+ printf("left/n");
+ }else if (spi.read() == 2) { //RIGHT
+ motorRIGHT = speed;
+ motorLEFT = 0;
+ motorDOWN = 0;
+ motorUP = 0;
+ printf("right/n");
+ }else { //stop
+ motorRIGHT = 0;
+ motorLEFT = 0;
+ motorDOWN = 0;
+ motorUP = 0;
+ }
+ int result = spi.read();
+ printf("%d\n",result);
+ }
+}
+