Difference between revisions of "Hovoriaci medvedík"
From Digitálne technológie výroby
Line 19: | Line 19: | ||
<hr /> | <hr /> | ||
<b>Ako na to?</b><br> | <b>Ako na to?</b><br> | ||
+ | |||
+ | ===Kód :=== | ||
+ | <hr /> | ||
+ | <syntaxhighlight lang="c"> | ||
+ | |||
+ | #include <SoftwareSerial.h> | ||
+ | #include <DFPlayer_Mini_Mp3.h> | ||
+ | SoftwareSerial mySerial(10, 11); // RX, TX | ||
+ | |||
+ | void setup () { | ||
+ | pinMode(3, INPUT); | ||
+ | Serial.begin (9600); | ||
+ | mySerial.begin (9600); | ||
+ | mp3_set_serial (mySerial); //set softwareSerial for DFPlayer-mini mp3 module | ||
+ | mp3_set_volume (15); | ||
+ | } | ||
+ | |||
+ | void loop () { | ||
+ | int button = 0; | ||
+ | |||
+ | unsigned int hlasitost = analogRead(A0); | ||
+ | hlasitost = map(hlasitost, 0, 1023, 0, 30); | ||
+ | Serial.println(hlasitost); | ||
+ | |||
+ | mp3_play(1); | ||
+ | mp3_set_volume (hlasitost); //0~30 | ||
+ | |||
+ | button = digitalRead(3); | ||
+ | if (button == 1) | ||
+ | { | ||
+ | mp3_pause (); | ||
+ | button = 1; | ||
+ | } | ||
+ | else if (button == 0) | ||
+ | { | ||
+ | mp3_play(1); | ||
+ | button = 0; | ||
+ | } | ||
+ | delay(5000); | ||
+ | } | ||
+ | </syntaxhighlight> |
Revision as of 16:02, 10 June 2020
Čo budeme potrebovať?
- Arduino Nano
- USB kábel
- Dotykový senzor
- Potenciometer
- Reproduktor
- MP3 + SD karta s vybranou nahrávkou
- Breadboard
- Kábliky
- Plyšový medveď, ktorý sa dá otvoriť
Prečo?
Ako na to?
Kód :
#include <SoftwareSerial.h>
#include <DFPlayer_Mini_Mp3.h>
SoftwareSerial mySerial(10, 11); // RX, TX
void setup () {
pinMode(3, INPUT);
Serial.begin (9600);
mySerial.begin (9600);
mp3_set_serial (mySerial); //set softwareSerial for DFPlayer-mini mp3 module
mp3_set_volume (15);
}
void loop () {
int button = 0;
unsigned int hlasitost = analogRead(A0);
hlasitost = map(hlasitost, 0, 1023, 0, 30);
Serial.println(hlasitost);
mp3_play(1);
mp3_set_volume (hlasitost); //0~30
button = digitalRead(3);
if (button == 1)
{
mp3_pause ();
button = 1;
}
else if (button == 0)
{
mp3_play(1);
button = 0;
}
delay(5000);
}