Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
arduino-block-course
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Stefan Gehr
arduino-block-course
Commits
7acb806b
Commit
7acb806b
authored
2 years ago
by
Mario Engelmann
Browse files
Options
Downloads
Plain Diff
Merge branch 'main' of gitlab.cs.fau.de:oz73ifuv/arduino-block-course into main
parents
7c3571e0
dcc41184
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
solarpump/mp3.ino
+39
-32
39 additions, 32 deletions
solarpump/mp3.ino
solarpump/solarpump.ino
+1
-2
1 addition, 2 deletions
solarpump/solarpump.ino
with
40 additions
and
34 deletions
solarpump/mp3.ino
+
39
−
32
View file @
7acb806b
...
...
@@ -3,37 +3,58 @@
static
SoftwareSerial
mp3
(
MP3RX
,
MP3TX
);
// the queue for playing sounds
#define QUEUESIZE 16
static
uint8_t
fileQueue
[
QUEUESIZE
];
static
uint8_t
currentPlayPos
=
0
;
// fileQueue[currentPlayPos] is currently played
static
uint8_t
currentQueueEnd
=
0
;
// fileQueue[currentQueue] is the next free place in the queue
// needs to be run once at the start
void
mp3Setup
(
void
)
{
mp3
.
begin
(
4800
);
pinMode
(
MP3BUSY
,
INPUT_PULLUP
);
//mp3.sendCommand(CMD_SEL_DEV, 0, 2); //select sd-card
}
// immediately play a file, ignoring any queue or BUSY pin
void
playFile
(
uint8_t
fileNumber
)
{
mp3
.
write
(
fileNumber
);
}
// play next file in queue if device is not busy anymore
// this should be constantly run in the loop-function
void
mp3Loop
(
void
)
{
// only do things if we were just playing a file
// and we are not busy
if
(
fileQueue
[
currentPlayPos
]
==
0
)
{
Serial
.
print
(
"No file was being played at pos "
);
Serial
.
println
(
currentPlayPos
);
/*
* the BUSY pin does not react immediately
* waitForBusy gets set to true when we play a file
* after that we wait until the BUSY pin reacts and becomes LOW
* now we can wait for the flank from LOW to HIGH => then the playing is done
*/
static
bool
waitForBusy
=
false
;
// next playing position in the queue
static
uint8_t
currentPlayPos
=
0
;
// check if we are busy
if
(
digitalRead
(
MP3BUSY
)
==
LOW
)
{
// we are done waiting for the BUSY pin
waitForBusy
=
false
;
return
;
}
if
(
digitalRead
(
MP3BUSY
)
==
LOW
)
{
Serial
.
println
(
"mp3 still busy"
);
/*
* BUSY pin is HIGH => we are not busy
* if waytForBusy == true, then we have just started playing a file,
* and we know that soon BUSY pin will be LOW
* if fileQueue[currentPlayPos] == 0, then there is no file in the queue
*/
if
(
waitForBusy
||
fileQueue
[
currentPlayPos
]
==
0
)
{
return
;
}
Serial
.
print
(
"Emptying at playpos "
);
Serial
.
println
(
currentPlayPos
);
// play the file at the current queue position
mp3
.
write
(
fileQueue
[
currentPlayPos
]);
// see explanation above
waitForBusy
=
true
;
// file can be removed off the queue
fileQueue
[
currentPlayPos
]
=
0
;
// advance one position further
...
...
@@ -42,36 +63,22 @@ void mp3Loop(void) {
if
(
currentPlayPos
==
QUEUESIZE
)
{
currentPlayPos
=
0
;
}
Serial
.
print
(
"new playpos "
);
Serial
.
println
(
currentPlayPos
);
// here is no file to play?
if
(
fileQueue
[
currentPlayPos
]
==
0
)
{
Serial
.
println
(
"There is no file to play here"
);
return
;
}
Serial
.
print
(
"Playing file "
);
Serial
.
print
(
fileQueue
[
currentPlayPos
]);
Serial
.
print
(
" at playpos "
);
Serial
.
println
(
currentPlayPos
);
mp3
.
write
(
fileQueue
[
currentPlayPos
]);
}
// add file to the queue and
play
start playing the queue
// add
a
file to the queue and start playing the queue
void
playFileQueue
(
uint8_t
fileNumber
)
{
Serial
.
print
(
"Adding "
);
Serial
.
print
(
fileNumber
);
Serial
.
print
(
" to queue at pos "
);
Serial
.
println
(
currentQueueEnd
);
// position of end of queue
static
uint8_t
currentQueueEnd
=
0
;
// save file to queue
fileQueue
[
currentQueueEnd
]
=
fileNumber
;
// the end is now one pos further
++
currentQueueEnd
;
// in case of wraparound
if
(
currentQueueEnd
==
QUEUESIZE
)
{
currentQueueEnd
=
0
;
}
Serial
.
print
(
"New queue end at pos "
);
Serial
.
println
(
currentQueueEnd
);
// start playing the queue if it is not playing already
mp3Loop
();
}
This diff is collapsed.
Click to expand it.
solarpump/solarpump.ino
+
1
−
2
View file @
7acb806b
...
...
@@ -187,10 +187,9 @@ void loop(void) {
if
(
checkButton
()
==
LOW
)
{
displayLight
(
true
);
Serial
.
println
(
"Adding temperature to queue"
);
playFileQueue
(
SOUND_TEMPERATURE
);
Serial
.
println
(
"Adding höchstwert to queue"
);
playFileQueue
(
SOUND_HOCHSTER_WERT
);
playFileQueue
(
SOUND_KOMMA
);
}
else
{
displayLight
(
false
);
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment