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
28e80c39
Commit
28e80c39
authored
2 years ago
by
Stefan Gehr
Browse files
Options
Downloads
Patches
Plain Diff
mp3 stuff
parent
f259e6c9
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
solarpump/mp3.h
+2
-0
2 additions, 0 deletions
solarpump/mp3.h
solarpump/mp3.ino
+63
-1
63 additions, 1 deletion
solarpump/mp3.ino
solarpump/pins.h
+1
-0
1 addition, 0 deletions
solarpump/pins.h
solarpump/solarpump.ino
+7
-8
7 additions, 8 deletions
solarpump/solarpump.ino
with
73 additions
and
9 deletions
solarpump/mp3.h
+
2
−
0
View file @
28e80c39
...
@@ -3,5 +3,7 @@
...
@@ -3,5 +3,7 @@
void
mp3Setup
(
void
);
void
mp3Setup
(
void
);
void
playFile
(
uint8_t
fileNumber
);
void
playFile
(
uint8_t
fileNumber
);
void
mp3Loop
(
void
);
void
playFileQueue
(
uint8_t
fileNumber
);
#endif
#endif
This diff is collapsed.
Click to expand it.
solarpump/mp3.ino
+
63
−
1
View file @
28e80c39
...
@@ -3,13 +3,75 @@
...
@@ -3,13 +3,75 @@
static
SoftwareSerial
mp3
(
MP3RX
,
MP3TX
);
static
SoftwareSerial
mp3
(
MP3RX
,
MP3TX
);
static
uint8_t
fileQueue
[
16
];
#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
void
mp3Setup
(
void
)
{
void
mp3Setup
(
void
)
{
mp3
.
begin
(
4800
);
mp3
.
begin
(
4800
);
pinMode
(
MP3BUSY
,
INPUT_PULLUP
);
//mp3.sendCommand(CMD_SEL_DEV, 0, 2); //select sd-card
//mp3.sendCommand(CMD_SEL_DEV, 0, 2); //select sd-card
}
}
void
playFile
(
uint8_t
fileNumber
)
{
void
playFile
(
uint8_t
fileNumber
)
{
mp3
.
write
(
fileNumber
);
mp3
.
write
(
fileNumber
);
}
}
// play next file in queue if device is not busy anymore
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
);
return
;
}
if
(
digitalRead
(
MP3BUSY
)
==
LOW
)
{
Serial
.
println
(
"mp3 still busy"
);
return
;
}
Serial
.
print
(
"Emptying at playpos "
);
Serial
.
println
(
currentPlayPos
);
fileQueue
[
currentPlayPos
]
=
0
;
// advance one position further
++
currentPlayPos
;
// in case of wraparound
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
void
playFileQueue
(
uint8_t
fileNumber
)
{
Serial
.
print
(
"Adding "
);
Serial
.
print
(
fileNumber
);
Serial
.
print
(
" to queue at pos "
);
Serial
.
println
(
currentQueueEnd
);
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
);
mp3Loop
();
}
This diff is collapsed.
Click to expand it.
solarpump/pins.h
+
1
−
0
View file @
28e80c39
...
@@ -8,6 +8,7 @@ const uint8_t T2DOWN = 5;
...
@@ -8,6 +8,7 @@ const uint8_t T2DOWN = 5;
const
uint8_t
PUMP1
=
8
;
const
uint8_t
PUMP1
=
8
;
const
uint8_t
PUMP2
=
9
;
const
uint8_t
PUMP2
=
9
;
const
uint8_t
BUTTON
=
10
;
const
uint8_t
BUTTON
=
10
;
const
uint8_t
MP3BUSY
=
11
;
const
uint8_t
MP3TX
=
12
;
const
uint8_t
MP3TX
=
12
;
const
uint8_t
MP3RX
=
13
;
const
uint8_t
MP3RX
=
13
;
#endif
#endif
This diff is collapsed.
Click to expand it.
solarpump/solarpump.ino
+
7
−
8
View file @
28e80c39
...
@@ -125,7 +125,7 @@ void displayText(float t1up_C, float t1down_C, bool pump1, float t2up_C, float t
...
@@ -125,7 +125,7 @@ void displayText(float t1up_C, float t1down_C, bool pump1, float t2up_C, float t
}
}
void
displayLight
(
bool
turnOn
)
{
void
displayLight
(
bool
turnOn
)
{
const
uint32_t
lightMillis
=
1
0000
;
const
uint32_t
lightMillis
=
3
0000
;
static
bool
curState
=
false
;
static
bool
curState
=
false
;
static
uint32_t
prevMillis
=
0
;
static
uint32_t
prevMillis
=
0
;
// turn on
// turn on
...
@@ -159,11 +159,14 @@ void loop(void) {
...
@@ -159,11 +159,14 @@ void loop(void) {
static
float
t2up_C
=
0.0
;
static
float
t2up_C
=
0.0
;
static
float
t2down_C
=
0.0
;
static
float
t2down_C
=
0.0
;
mp3Loop
();
if
(
checkButton
()
==
LOW
)
{
if
(
checkButton
()
==
LOW
)
{
displayLight
(
true
);
displayLight
(
true
);
playFile
(
SOUND_TEMPERATURE
);
Serial
.
println
(
"Adding temperature to queue"
);
delay
(
2000
);
playFileQueue
(
SOUND_TEMPERATURE
);
playFile
(
SOUND_HOCHSTER_WERT
);
Serial
.
println
(
"Adding höchstwert to queue"
);
playFileQueue
(
SOUND_HOCHSTER_WERT
);
}
else
{
}
else
{
displayLight
(
false
);
displayLight
(
false
);
}
}
...
@@ -171,19 +174,15 @@ void loop(void) {
...
@@ -171,19 +174,15 @@ void loop(void) {
if
(
t1up
(
&
t1up_C
)
==
LONG_TIME_ERROR
||
t1down
(
&
t1down_C
)
==
LONG_TIME_ERROR
)
{
if
(
t1up
(
&
t1up_C
)
==
LONG_TIME_ERROR
||
t1down
(
&
t1down_C
)
==
LONG_TIME_ERROR
)
{
// TODO: Warning sound
// TODO: Warning sound
// Turn pump on to be safe
// Turn pump on to be safe
Serial
.
println
(
"LONG TIME ERROR for solar system 1"
);
digitalWrite
(
PUMP1
,
HIGH
);
digitalWrite
(
PUMP1
,
HIGH
);
}
else
{
}
else
{
Serial
.
println
(
"controlPump for solar system 1"
);
controlPump
(
PUMP1
,
t1up_C
,
t1down_C
);
controlPump
(
PUMP1
,
t1up_C
,
t1down_C
);
}
}
if
(
t2up
(
&
t2up_C
)
==
LONG_TIME_ERROR
||
t2down
(
&
t2down_C
)
==
LONG_TIME_ERROR
)
{
if
(
t2up
(
&
t2up_C
)
==
LONG_TIME_ERROR
||
t2down
(
&
t2down_C
)
==
LONG_TIME_ERROR
)
{
// TODO: Warning sound
// TODO: Warning sound
// Turn pump on to be safe
// Turn pump on to be safe
Serial
.
println
(
"LONG TIME ERROR for solar system 2"
);
digitalWrite
(
PUMP2
,
HIGH
);
digitalWrite
(
PUMP2
,
HIGH
);
}
else
{
}
else
{
Serial
.
println
(
"controlPump for solar system 2"
);
controlPump
(
PUMP2
,
t2up_C
,
t2down_C
);
controlPump
(
PUMP2
,
t2up_C
,
t2down_C
);
}
}
...
...
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