1)実体配線図とスケッチを示す.
#include <LiquidCrystal.h>
#define VR1 0
LiquidCrystal lcd(12,11,5,4,3,2);
void setup(){
lcd.begin(16,2);
pinMode(0,OUTPUT); //信号用ピン
pinMode(1,OUTPUT); //信号用ピン
}
void loop(){
int val;
float f;
val = analogRead(VR1)/2;
if(val>=255 && val<=256){ //静止
digitalWrite(0,LOW);
digitalWrite(1,LOW);
lcd.setCursor(0,0);
lcd.print("STOP ");
}else if(val>256){ //正転
digitalWrite(0,HIGH);
digitalWrite(1,LOW);
analogWrite(6,val-256);
lcd.setCursor(0,0);
lcd.print("RIGHT");
}else{ //逆転
digitalWrite(0,LOW);
digitalWrite(1,HIGH);
analogWrite(6,255-val);
lcd.setCursor(0,0);
lcd.print("LEFT ");
}
lcd.setCursor(0,1);
lcd.print(val);
}
2)解説
作成中です.