ポテンショメータの変換

Dependencies:   USBDevice mbed

Fork of USBSerial_HelloWorld by Samuel Mokrani

Committer:
mitsuhiroYabu
Date:
Mon May 22 01:05:31 2017 +0000
Revision:
10:35941a39f02d
Parent:
9:d88699a0905a
???????????

Who changed what in which revision?

UserRevisionLine numberNew contents of line
samux 7:5e693654d5b4 1 #include "mbed.h"
samux 7:5e693654d5b4 2 #include "USBSerial.h"
samux 7:5e693654d5b4 3
samux 7:5e693654d5b4 4 //Virtual serial port over USB
mitsuhiroYabu 10:35941a39f02d 5 //USBSerial serial;
mitsuhiroYabu 10:35941a39f02d 6 DigitalOut myled(LED1);
mitsuhiroYabu 10:35941a39f02d 7 AnalogIn potentiometer(p15);
mitsuhiroYabu 10:35941a39f02d 8 float pot_val = 0.5;
mitsuhiroYabu 10:35941a39f02d 9 float result = 0.5;
mitsuhiroYabu 10:35941a39f02d 10 Serial pc(USBTX, USBRX);
mitsuhiroYabu 10:35941a39f02d 11 #define MAX 0.28
mitsuhiroYabu 10:35941a39f02d 12 #define MIN 0.62
samux 7:5e693654d5b4 13 int main(void) {
samux 9:d88699a0905a 14
samux 7:5e693654d5b4 15 while(1)
samux 7:5e693654d5b4 16 {
mitsuhiroYabu 10:35941a39f02d 17 myled = 1;
mitsuhiroYabu 10:35941a39f02d 18 pot_val = potentiometer.read();
mitsuhiroYabu 10:35941a39f02d 19 result = (pot_val-MIN)/(MAX-MIN);
mitsuhiroYabu 10:35941a39f02d 20 pc.printf("pot_val=%2.2f conversion=%2.2f angle=%3.2f[deg] \r\n",pot_val,result,result*360);
mitsuhiroYabu 10:35941a39f02d 21 //serial.printf("I am a virtual serial port\r\n");
mitsuhiroYabu 10:35941a39f02d 22 wait_ms(50);
mitsuhiroYabu 10:35941a39f02d 23 myled = 0;
mitsuhiroYabu 10:35941a39f02d 24 wait_ms(50);
samux 7:5e693654d5b4 25 }
samux 7:5e693654d5b4 26 }