taka yamanouchi / Mbed 2 deprecated Nucleo_minirobo_con

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
sink
Date:
Mon Oct 05 10:37:51 2020 +0000
Child:
1:79522b611923
Commit message:
yguy

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Mon Oct 05 10:37:51 2020 +0000
@@ -0,0 +1,80 @@
+#include "mbed.h"
+#include "string"
+#define INT_TIME 0.02
+
+
+Ticker timer;
+RawSerial pc(USBTX,USBRX,115200);
+RawSerial Master(D5,D4,115200);
+
+DigitalIn sw2(D2);
+DigitalIn sw3(D3);
+DigitalIn sw6(D6);
+DigitalIn sw7(D7);
+DigitalIn sw8(D8);
+DigitalIn sw9(D9);
+DigitalIn sw10(D10);
+
+AnalogIn joyR_x(A6);
+AnalogIn joyR_y(A5);
+AnalogIn joyL_x(A4);
+AnalogIn joyL_y(A3);
+
+bool per_rotR, pre_rotL, pre_up, pre_down, pre_handR, pre_handL, pre_other;
+
+bool sw_in(int sw, int pre_sw){
+    bool rt_sw;
+    if (sw == true && pre_sw == false) rt_sw = true;
+    else rt_sw = false;
+    return rt_sw;
+}
+
+void timer_warikomi(){
+    
+    double d_joyx = joyR_x.read();
+    double d_joyy = joyR_y.read();
+    
+    bool rotR = sw2.read();
+    bool rotL = sw3.read();
+    bool up = sw6.read();
+    bool down = sw7.read();
+    bool handR = sw8.read();
+    bool handL = sw9.read();
+    bool other = sw10.read();
+    
+    char buttons = 0b00000000;
+    
+    if(sw_in(up,pre_up))       buttons |= 0b00000001;
+    if(sw_in(down,pre_down))   buttons |= 0b00000010;
+    if(sw_in(handR,pre_handR)) buttons |= 0b00000100;
+    if(sw_in(handL,pre_handL)) buttons |= 0b00001000;
+    if(sw_in(other,pre_other)) buttons |= 0b00010000;
+    
+    char joyx = char(int(255.0 * d_joyx));
+    char joyy = char(int(255.0 * d_joyy));
+    char rot  = char(127 + 100*sw_in(rotR,per_rotR)- 100*sw_in(rotL,pre_rotL));
+    
+    pc.printf("%c%c%c%c\n",joyx,joyy,rot,buttons);
+    
+    Master.putc(joyx);
+    Master.putc(joyy);
+    Master.putc(rot);
+    Master.putc(buttons);
+    Master.putc('\n');
+    
+    per_rotR = rotR;
+    pre_rotL = rotL;
+    pre_up = up;
+    pre_down = down;
+    pre_handR = handR;
+    pre_handL = handL;
+    pre_other = other;
+}
+
+int main()
+{
+    
+    timer.attach(&timer_warikomi,INT_TIME);
+    
+    while(true) {}
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Mon Oct 05 10:37:51 2020 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/mbed_official/code/mbed/builds/65be27845400
\ No newline at end of file