hi

Dependencies:   mbed Servo

Files at this revision

API Documentation at this revision

Comitter:
injokim
Date:
Sun Dec 09 01:57:59 2018 +0000
Commit message:
hi;

Changed in this revision

Hall_sesor.cpp Show annotated file Show diff for this revision Revisions of this file
Laser.cpp Show annotated file Show diff for this revision Revisions of this file
Servo.lib Show annotated file Show diff for this revision Revisions of this file
WIFI.cpp Show annotated file Show diff for this revision Revisions of this file
header.h Show annotated file Show diff for this revision Revisions of this file
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
diff -r 000000000000 -r b9dc28a0bfcc Hall_sesor.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Hall_sesor.cpp	Sun Dec 09 01:57:59 2018 +0000
@@ -0,0 +1,31 @@
+#include "header.h"
+
+DigitalIn   hall_value(D15);
+
+void Hall_sensor()
+{
+    int meas,rev,flag,dist;
+    
+    flag = 0;
+    rev = 0;
+    int dm = 680; // diameter
+
+    meas = hall_value.read();
+    if(meas == 0 && flag ==0)
+    {
+        rev += 1;
+        flag = 1;
+    }
+        
+    else
+    {
+        flag = 0;   
+    }
+        
+    dist = dm * rev;
+        
+    printf("measure = %d mV\n\r", meas);
+    printf("measure = %d mV\n\r", dist);
+    wait(0.2); // 200 ms
+
+}
\ No newline at end of file
diff -r 000000000000 -r b9dc28a0bfcc Laser.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Laser.cpp	Sun Dec 09 01:57:59 2018 +0000
@@ -0,0 +1,39 @@
+#include "header.h"
+
+DigitalIn   LaserSensor(D2);
+DigitalOut  my_led(LED1);
+PwmOut      my_servo(PB_0);
+
+int Laser()
+{ 
+    int cmd; 
+    
+    if(LaserSensor == 1)
+    {
+        my_led = 0;
+        cmd=0;
+    }
+                                  
+    else
+    {
+        my_led = 1;
+        cmd=1;
+    }
+    wait(0.1);
+    return cmd;
+}
+
+void Laser_servo(int i)
+{
+    if (i==1)
+      {  
+        my_servo.period_ms(20);
+        my_servo.write(0.1);
+      }
+      
+      else
+      {
+        my_servo.period_ms(20);
+        my_servo.write(0.25);
+      }
+}
\ No newline at end of file
diff -r 000000000000 -r b9dc28a0bfcc Servo.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Servo.lib	Sun Dec 09 01:57:59 2018 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/simon/code/Servo/#36b69a7ced07
diff -r 000000000000 -r b9dc28a0bfcc WIFI.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/WIFI.cpp	Sun Dec 09 01:57:59 2018 +0000
@@ -0,0 +1,52 @@
+#include "header.h"
+
+Serial pc(SERIAL_TX, SERIAL_RX,115200);
+Serial board(PA_11, PA_12,115200);
+char in;
+    
+void wifi_init()
+{
+    pc.attach(&RX_interrupt1);
+    board.attach(&RX_interrupt2);
+    
+    board.printf("+++");
+    wait(0.5);
+    
+    board.printf("AT+E\r");
+    wait(0.5);
+    
+    board.printf("AT+WMODE=STA\r");
+    wait(0.5);
+    
+    board.printf("AT+TMODE=cmd\r");
+    wait(0.5);
+    
+    board.printf("AT+WSSSID=iPhone\r"); //아까 세팅한 AP이름으로
+    wait(0.5);
+    
+    board.printf("AT+WSKEY=WPA2PSK,AES,123456780\r");
+    wait(0.5);
+    
+    board.printf("AT+NETP=TCP,CLIENT,8899,13.124.51.161\r");
+    wait(0.5);
+    
+    board.printf("AT+TMODE=throughput\r");
+    wait(0.5);
+    
+    board.printf("AT+ENTM\r");
+    wait(0.5);
+}
+
+void RX_interrupt1(){
+    in = pc.getc();
+    board.putc(in);
+}
+
+void RX_interrupt2(){
+    pc.putc(board.getc());
+}
+
+void wifi_print()
+{
+    board.printf("Obstacle!!");
+}
\ No newline at end of file
diff -r 000000000000 -r b9dc28a0bfcc header.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/header.h	Sun Dec 09 01:57:59 2018 +0000
@@ -0,0 +1,11 @@
+#include "mbed.h"
+
+int Laser();
+void DC_motor();
+void Laser_servo(int i);
+void Run_DC(int i);
+void Hall_sensor();
+void wifi_init();
+void RX_interrupt1();
+void RX_interrupt2();
+void wifi_print();
\ No newline at end of file
diff -r 000000000000 -r b9dc28a0bfcc main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Sun Dec 09 01:57:59 2018 +0000
@@ -0,0 +1,52 @@
+
+//------------------------------------
+// Hyperterminal configuration
+// 9600 bauds, 8-bit data, no parity
+//------------------------------------
+
+#include "header.h"
+
+PwmOut      mypwm(A1);
+
+int main() 
+{ 
+    int i;
+    
+   //DC motor PWM set
+    mypwm.period_ms(10);
+    mypwm.pulsewidth_ms(1);
+    
+    //Set Wifi
+    wifi_init();
+  
+    while(1)
+    {
+       i= Laser();
+       Laser_servo(i);
+       
+       Hall_sensor();
+       Run_DC(i);
+       
+       if(i==1)
+       {
+           wifi_print();
+           wait(0.05);
+        }
+    }
+}
+
+
+void Run_DC(int i)
+{
+    if(i==1)
+    {
+        mypwm.write(0.5); //  slow
+        wait(0.01);
+    }
+    
+    else
+    {  
+        mypwm.write(0.1); // fast
+        wait(0.01);
+    }
+}
\ No newline at end of file
diff -r 000000000000 -r b9dc28a0bfcc mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Sun Dec 09 01:57:59 2018 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/mbed_official/code/mbed/builds/3a7713b1edbc
\ No newline at end of file