31 lines
468 B
C++
31 lines
468 B
C++
#include "Motor.h"
|
|
|
|
Motor motor;
|
|
|
|
void setup() {
|
|
motor.attach(5,6);
|
|
Serial.begin(9600);
|
|
Serial.print("format : [0-255][ab]");
|
|
}
|
|
|
|
void loop() {
|
|
static int v = 0;
|
|
|
|
if ( Serial.available() ) {
|
|
char ch = Serial.read();
|
|
|
|
switch(ch) {
|
|
case '0'...'9':
|
|
v = v * 10 + ch - '0';
|
|
break;
|
|
case 'a':
|
|
motor.speed(v);
|
|
v = 0;
|
|
break;
|
|
case 'b':
|
|
motor.speed(-v);
|
|
v = 0;
|
|
break;
|
|
}
|
|
}
|
|
}
|