From 965fbc7b81bd3ba27c37b305470fdc46ce22e905 Mon Sep 17 00:00:00 2001 From: Roald Batts Date: Thu, 26 Jan 2023 20:20:44 -0500 Subject: [PATCH] got the basics of the servo motor working --- soler_chager.ino | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/soler_chager.ino b/soler_chager.ino index a815c43..491b0da 100644 --- a/soler_chager.ino +++ b/soler_chager.ino @@ -8,6 +8,7 @@ #define LED 3 #define button 2 #define buzzer 6 +#define servoPin 10 BH1750 lightMeter; DHT dht(DHT11_PIN, DHT11); @@ -23,6 +24,7 @@ void setup() pinMode(LED, OUTPUT); //initialize digital pin LED as an output. pinMode(button, INPUT); pinMode(buzzer, OUTPUT); + pinMode(servoPin,OUTPUT); Serial.print("init lcd\n"); lcd.init(); lcd.backlight(); @@ -30,7 +32,7 @@ void setup() lcd.printstr("Hello, World!"); lcd.setCursor(0,1); lcd.printstr("hello, Roald!"); - + dht.begin(20); Serial.print("done setting up!\n"); @@ -48,6 +50,18 @@ void loop(){ //Serial.print(count); //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); if (lightReadL1 > 300){ digitalWrite(LED, HIGH); @@ -142,3 +156,12 @@ void blink() digitalWrite(LED,LOW); //turn the LED off by making the voltage LOW 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); + } +}