use servo library for both motors
This commit is contained in:
parent
965fbc7b81
commit
66ab550699
1 changed files with 19 additions and 22 deletions
|
@ -2,13 +2,15 @@
|
|||
#include <LiquidCrystal_I2C.h>
|
||||
#include <DHT.h>
|
||||
#include <BH1750.h>
|
||||
#include <Servo.h>
|
||||
|
||||
#define DHT11_PIN 7
|
||||
#define photoL1 A0
|
||||
#define LED 3
|
||||
#define button 2
|
||||
#define buzzer 6
|
||||
#define servoPin 10
|
||||
#define circleServoPin 9
|
||||
#define tiltServoPin 10
|
||||
|
||||
BH1750 lightMeter;
|
||||
DHT dht(DHT11_PIN, DHT11);
|
||||
|
@ -16,6 +18,8 @@ volatile int buttonState;
|
|||
volatile int lightReadL1 = 0;
|
||||
int count;
|
||||
LiquidCrystal_I2C lcd(0x27, 16, 2);
|
||||
Servo circleServo;
|
||||
Servo tiltServo;
|
||||
|
||||
void setup()
|
||||
{
|
||||
|
@ -24,7 +28,9 @@ void setup()
|
|||
pinMode(LED, OUTPUT); //initialize digital pin LED as an output.
|
||||
pinMode(button, INPUT);
|
||||
pinMode(buzzer, OUTPUT);
|
||||
pinMode(servoPin,OUTPUT);
|
||||
circleServo.attach(circleServoPin);
|
||||
tiltServo.attach(tiltServoPin);
|
||||
|
||||
Serial.print("init lcd\n");
|
||||
lcd.init();
|
||||
lcd.backlight();
|
||||
|
@ -49,18 +55,18 @@ void loop(){
|
|||
//Serial.print("[");
|
||||
//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);
|
||||
|
||||
delay(300);
|
||||
for (int i = 180; i > 0; i--) {
|
||||
circleServo.write(i);
|
||||
tiltServo.write(i);
|
||||
delay(10);
|
||||
}
|
||||
for (int i = 0; i < 180; i++) {
|
||||
circleServo.write(i);
|
||||
tiltServo.write(i);
|
||||
delay(10);
|
||||
}
|
||||
|
||||
lightReadL1 = analogRead(photoL1);
|
||||
if (lightReadL1 > 300){
|
||||
|
@ -156,12 +162,3 @@ 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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue