エレキジャックweb mbed入門 サーボを動かそう 課題3です。'*'をサーボの動きに合わせて棒グラフとして表示します。

Dependencies:   mbed

Revision:
0:0a937a97f30f
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Thu Aug 18 23:07:55 2011 +0000
@@ -0,0 +1,39 @@
+//Servo test04 Vr_control => AD=>Servo
+// '*' bar graph
+#include "mbed.h"
+#include "TextLCD0420.h"
+
+#define ON 1
+#define OFF 0
+
+DigitalOut mled0(LED1);
+DigitalOut mled1(LED2);
+AnalogIn vr_adc(p15);
+PwmOut servo1(p21);
+
+TextLCD lcd(p24, p25, p26, p27, p28, p29, p30,20,4); // rs, rw, e, d0, d1, d2, d3
+
+int main() {
+  int i;
+  float pwidth,vr_data;
+  lcd.cls();
+  lcd.locate(0,0);
+  lcd.printf("*** Servo test ****\n");         
+  servo1.period_ms(20);
+
+  while(1){   
+    vr_data=vr_adc.read()/1000;
+    pwidth=vr_data+0.001;
+      servo1.pulsewidth(pwidth);
+      lcd.locate(0,1);
+      lcd.printf("----+----:%2.2f%ms",pwidth*1000);
+      lcd.locate(0,2);
+      lcd.printf("                    ");
+      lcd.locate(0,2);
+      for(i=0;i<vr_data*10000-1;i++){
+        lcd.printf("*");
+      }
+      
+  }//while    
+}//main      
+