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 <LiquidCrystal_I2C.h>
|
||||||
#include <DHT.h>
|
#include <DHT.h>
|
||||||
#include <BH1750.h>
|
#include <BH1750.h>
|
||||||
|
#include <Servo.h>
|
||||||
|
|
||||||
#define DHT11_PIN 7
|
#define DHT11_PIN 7
|
||||||
#define photoL1 A0
|
#define photoL1 A0
|
||||||
#define LED 3
|
#define LED 3
|
||||||
#define button 2
|
#define button 2
|
||||||
#define buzzer 6
|
#define buzzer 6
|
||||||
#define servoPin 10
|
#define circleServoPin 9
|
||||||
|
#define tiltServoPin 10
|
||||||
|
|
||||||
BH1750 lightMeter;
|
BH1750 lightMeter;
|
||||||
DHT dht(DHT11_PIN, DHT11);
|
DHT dht(DHT11_PIN, DHT11);
|
||||||
|
@ -16,6 +18,8 @@ volatile int buttonState;
|
||||||
volatile int lightReadL1 = 0;
|
volatile int lightReadL1 = 0;
|
||||||
int count;
|
int count;
|
||||||
LiquidCrystal_I2C lcd(0x27, 16, 2);
|
LiquidCrystal_I2C lcd(0x27, 16, 2);
|
||||||
|
Servo circleServo;
|
||||||
|
Servo tiltServo;
|
||||||
|
|
||||||
void setup()
|
void setup()
|
||||||
{
|
{
|
||||||
|
@ -24,7 +28,9 @@ 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);
|
circleServo.attach(circleServoPin);
|
||||||
|
tiltServo.attach(tiltServoPin);
|
||||||
|
|
||||||
Serial.print("init lcd\n");
|
Serial.print("init lcd\n");
|
||||||
lcd.init();
|
lcd.init();
|
||||||
lcd.backlight();
|
lcd.backlight();
|
||||||
|
@ -50,17 +56,17 @@ void loop(){
|
||||||
//Serial.print(count);
|
//Serial.print(count);
|
||||||
//Serial.print("] hey\n");
|
//Serial.print("] hey\n");
|
||||||
|
|
||||||
|
delay(300);
|
||||||
Serial.println("0");
|
for (int i = 180; i > 0; i--) {
|
||||||
servopulse(servoPin,0);
|
circleServo.write(i);
|
||||||
delay(500);
|
tiltServo.write(i);
|
||||||
Serial.println("90");
|
delay(10);
|
||||||
servopulse(servoPin,90);
|
}
|
||||||
delay(500);
|
for (int i = 0; i < 180; i++) {
|
||||||
Serial.println("180");
|
circleServo.write(i);
|
||||||
servopulse(servoPin,180);
|
tiltServo.write(i);
|
||||||
delay(500);
|
delay(10);
|
||||||
|
}
|
||||||
|
|
||||||
lightReadL1 = analogRead(photoL1);
|
lightReadL1 = analogRead(photoL1);
|
||||||
if (lightReadL1 > 300){
|
if (lightReadL1 > 300){
|
||||||
|
@ -156,12 +162,3 @@ 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