////////////////////
// Arduino Counter.
// inf102 S.H 2025.
////////////////////
#include <Servo.h>
Servo myservo;
const int SV_PIN = 7;
const int PIN_ANALOG_INPUT = 5;
static bool t=false;
void setup() {
myservo.attach(SV_PIN, 500, 2400);
Serial.begin( 9600 );
}
void loop() {
int i = analogRead( PIN_ANALOG_INPUT );
float f = i * 5.0 / 1024.0;
Serial.print (f);
if ( f>=4.0) {
Serial.print ("レーザ受光中\r\n");
t=false;
}
else{
Serial.print ("レーザ非受光\r\n");
if (t==false){
myservo.attach(SV_PIN, 500, 2400);
myservo.write(33);
delay(300);
myservo.write(0);
delay(300);
myservo.detach();
t=true;
}
}
delay (50);
}