-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArduinoCode
More file actions
51 lines (47 loc) · 1.23 KB
/
ArduinoCode
File metadata and controls
51 lines (47 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include <Servo.h> //library to control servo
#include <SoftwareSerial.h>
#include <DFPlayer_Mini_Mp3.h> //library to control dfplayer mini
#include <MsTimer2.h> //to use timer
Servo servo1;
int grado = 10;
int sensorValue;
int count = 0;
int digit = 0;
// the setup routine runs once when you press reset:
void setup() {
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
servo1.attach(2); //servo motor connected to D2
servo1.write(grado);
mp3_set_serial (Serial); //set Serial for DFPlayer-mini mp3 module
delay(1); //wait 1ms for mp3 module to set volume
mp3_set_volume (25); //set volume
}
void robotics(){
digit = 1;
}
// the loop routine runs over and over again forever:
void loop() {
sensorValue = analogRead(A0); // read the input on analog pin 0:
// print out the value you read:
grado = sensorValue/5,68;
Serial.println(sensorValue);
if(sensorValue > 150){
Serial.print("robotics");
servo1.write(grado+100);
delay(300);
count++;
}
if(count==1){
MsTimer2::set(5000, robotics);//set Timer 5 sec
MsTimer2::start();
if(digit ==1){
grado=10;
mp3_play (20);//play 0020.mp3
delay (3000);
servo1.write(grado);
count = 0;
digit=0;
}
}
}