|
#define IR_pin 0
int IR_val = 0;
float val = 0;
int pwm_a = 3;
int pwm_b = 11;
int dir_a = 12;
int dir_b = 13;
void setup() {
Serial.begin(9600);
pinMode(pwm_a, OUTPUT);
pinMode(pwm_b, OUTPUT);
pinMode(dir_a, OUTPUT);
pinMode(dir_b, OUTPUT);
}
void loop()
{
val = analogRead(0) ;
val = val*5/1024; //記得換算成電壓
val = 12.726*pow(val,-1.061);
digitalWrite(dir_a, HIGH);
digitalWrite(dir_b, HIGH);
delay(100);
analogWrite(pwm_a, 255);
analogWrite(pwm_b, 255);
delay(100);
if (IR_val < 50) // obstacle detected
{
IR_val = analogRead(IR_pin);
// Stop both motors...
analogWrite(pwm_a, 10);
analogWrite(pwm_b, 10);
delay(1000); // ...and pause for a second
}
}
可以編譯但是 ,功能不是原程式的方式
不知道該怎樣解決
也想請問高手們如何把讀取的電壓值轉換成公分
謝謝大家的解答 |
|