got the basics of the servo motor working
This commit is contained in:
parent
8a69770dbd
commit
965fbc7b81
1 changed files with 24 additions and 1 deletions
|
@ -8,6 +8,7 @@
|
||||||
#define LED 3
|
#define LED 3
|
||||||
#define button 2
|
#define button 2
|
||||||
#define buzzer 6
|
#define buzzer 6
|
||||||
|
#define servoPin 10
|
||||||
|
|
||||||
BH1750 lightMeter;
|
BH1750 lightMeter;
|
||||||
DHT dht(DHT11_PIN, DHT11);
|
DHT dht(DHT11_PIN, DHT11);
|
||||||
|
@ -23,6 +24,7 @@ void setup()
|
||||||
pinMode(LED, OUTPUT); //initialize digital pin LED as an output.
|
pinMode(LED, OUTPUT); //initialize digital pin LED as an output.
|
||||||
pinMode(button, INPUT);
|
pinMode(button, INPUT);
|
||||||
pinMode(buzzer, OUTPUT);
|
pinMode(buzzer, OUTPUT);
|
||||||
|
pinMode(servoPin,OUTPUT);
|
||||||
Serial.print("init lcd\n");
|
Serial.print("init lcd\n");
|
||||||
lcd.init();
|
lcd.init();
|
||||||
lcd.backlight();
|
lcd.backlight();
|
||||||
|
@ -48,6 +50,18 @@ void loop(){
|
||||||
//Serial.print(count);
|
//Serial.print(count);
|
||||||
//Serial.print("] hey\n");
|
//Serial.print("] hey\n");
|
||||||
|
|
||||||
|
|
||||||
|
Serial.println("0");
|
||||||
|
servopulse(servoPin,0);
|
||||||
|
delay(500);
|
||||||
|
Serial.println("90");
|
||||||
|
servopulse(servoPin,90);
|
||||||
|
delay(500);
|
||||||
|
Serial.println("180");
|
||||||
|
servopulse(servoPin,180);
|
||||||
|
delay(500);
|
||||||
|
|
||||||
|
|
||||||
lightReadL1 = analogRead(photoL1);
|
lightReadL1 = analogRead(photoL1);
|
||||||
if (lightReadL1 > 300){
|
if (lightReadL1 > 300){
|
||||||
digitalWrite(LED, HIGH);
|
digitalWrite(LED, HIGH);
|
||||||
|
@ -142,3 +156,12 @@ void blink()
|
||||||
digitalWrite(LED,LOW); //turn the LED off by making the voltage LOW
|
digitalWrite(LED,LOW); //turn the LED off by making the voltage LOW
|
||||||
delay(1000); //wait for a second
|
delay(1000); //wait for a second
|
||||||
}
|
}
|
||||||
|
void servopulse(int pin, int myangle){
|
||||||
|
int pulsewidth = map(myangle, 0, 180, 500, 2500);
|
||||||
|
for (int i = 0; i < 10; i++){
|
||||||
|
digitalWrite(pin,HIGH);
|
||||||
|
delayMicroseconds(pulsewidth);
|
||||||
|
digitalWrite(pin,LOW);
|
||||||
|
delay(20-pulsewidth/1000);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue