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
76e380a4
Commit
76e380a4
authored
2 years ago
by
Mario Engelmann
Browse files
Options
Downloads
Plain Diff
stufff
parents
3fe725e0
728508c5
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
solarpump/sayNumber.h
+7
-0
7 additions, 0 deletions
solarpump/sayNumber.h
solarpump/sayNumber.ino
+156
-0
156 additions, 0 deletions
solarpump/sayNumber.ino
solarpump/solarpump.ino
+8
-0
8 additions, 0 deletions
solarpump/solarpump.ino
with
171 additions
and
0 deletions
solarpump/sayNumber.h
0 → 100644
+
7
−
0
View file @
76e380a4
#ifndef SAYNUMBERS_H
#define SAYNUMBERS_H
void
sayNumber
(
int32_t
number
);
void
sayNumber
(
double
number
,
uint8_t
roundDigits
);
#endif
This diff is collapsed.
Click to expand it.
solarpump/sayNumber.ino
0 → 100644
+
156
−
0
View file @
76e380a4
#include
"mp3.h"
#include
"soundFiles.h"
// says the digit
static
void
sayDigit
(
int8_t
number
)
{
switch
(
number
)
{
case
0
:
playFileQueue
(
SOUND_NULL
);
break
;
case
1
:
playFileQueue
(
SOUND_EINS
);
break
;
case
2
:
playFileQueue
(
SOUND_ZWEI
);
break
;
case
3
:
playFileQueue
(
SOUND_DREI
);
break
;
case
4
:
playFileQueue
(
SOUND_VIER
);
break
;
case
5
:
playFileQueue
(
SOUND_FUNF
);
break
;
case
6
:
playFileQueue
(
SOUND_SECHS
);
break
;
case
7
:
playFileQueue
(
SOUND_SIEBEN
);
break
;
case
8
:
playFileQueue
(
SOUND_ACHT
);
break
;
case
9
:
playFileQueue
(
SOUND_NEUN
);
break
;
default:
break
;
}
}
// Same as sayNumber(int32_t n) only for 1 it says EIN instead of EINS.
static
void
sayPreNumber
(
int32_t
number
)
{
if
(
number
==
1
)
playFileQueue
(
SOUND_EIN
);
else
sayNumber
(
number
);
}
// Same as sayNumber(int32_t n) only for 0 it does nothing
static
void
sayAftNumber
(
int32_t
number
)
{
if
(
number
)
sayNumber
(
number
);
}
// say integer number
void
sayNumber
(
int32_t
number
)
{
// Negative numbers are spoken the same way as positive numbers only with "Minus" at the beginning.
if
(
number
<
0
)
{
playFileQueue
(
SOUND_MINUS
);
sayNumber
(
-
number
);
// 1-digit numbers
}
else
if
(
number
<
10
)
{
sayDigit
(
number
);
// 2-digit numbers
}
else
if
(
number
<
100
)
{
// extra cases for 11 and 12
switch
(
number
)
{
case
11
:
playFileQueue
(
SOUND_ELF
);
break
;
case
12
:
playFileQueue
(
SOUND_ZWOLF
);
break
;
default:
// German specific: Say the 1-digit first, then the 10-digit
int32_t
tens
=
number
/
10
;
int32_t
ones
=
number
-
10
*
tens
;
// first say the 1-digit
if
(
ones
)
{
sayPreNumber
(
ones
);
// UND only for numbers > 20. (VierUNDzwanzig, but not VierUNDzehn.)
if
(
tens
>=
2
)
playFileQueue
(
SOUND_UND
);
}
// then say the 10-digit
switch
(
tens
)
{
case
1
:
playFileQueue
(
SOUND_ZEHN
);
break
;
case
2
:
playFileQueue
(
SOUND_ZWANZIG
);
break
;
case
3
:
playFileQueue
(
SOUND_DREISSIG
);
break
;
case
4
:
playFileQueue
(
SOUND_VIERZIG
);
break
;
case
5
:
playFileQueue
(
SOUND_FUNFZIG
);
break
;
case
6
:
playFileQueue
(
SOUND_SECHZIG
);
break
;
case
7
:
playFileQueue
(
SOUND_SIEBZIG
);
break
;
case
8
:
playFileQueue
(
SOUND_ACHTZIG
);
break
;
case
9
:
playFileQueue
(
SOUND_NEUNZIG
);
break
;
default:
break
;
}
break
;
}
// 3-digit numbers
}
else
{
int32_t
hundreds
=
number
/
100
;
sayPreNumber
(
hundreds
);
playFileQueue
(
SOUND_HUNDERT
);
sayAftNumber
(
number
-
100
*
hundreds
);
}
}
/*
* Say any number in the int-range between -999999 and 999999 (in German)
* double n: The number to say
* uint8_t roundDigits: How many digits after the comma should be said (last one will get rounded)
* Example: sayNumber(34.236, 2) will say "Vierunddreißig Komma Zwei Vier"
*/
void
sayNumber
(
double
number
,
uint8_t
roundDigits
)
{
// do the rounding at the correct digit
number
=
round
(
number
*
pow
(
10
,
roundDigits
))
/
pow
(
10
,
roundDigits
);
// say the pre-decimal digits
int32_t
int_n
=
(
int32_t
)
number
;
sayNumber
(
int_n
);
// say the decimals
if
(
roundDigits
)
{
number
=
abs
(
number
-
int_n
);
playFileQueue
(
SOUND_KOMMA
);
for
(
int8_t
digit
=
1
;
digit
<=
roundDigits
;
++
digit
)
{
double
d_newDigit
=
number
*
pow
(
10
,
digit
)
-
10
*
(
int32_t
)(
number
*
pow
(
10
,
digit
-
1
));
int8_t
newDigit
;
// round correctly for the last digit
if
(
digit
==
roundDigits
)
newDigit
=
(
int8_t
)
round
(
d_newDigit
);
else
newDigit
=
(
int8_t
)
d_newDigit
;
sayDigit
(
newDigit
);
}
}
}
This diff is collapsed.
Click to expand it.
solarpump/solarpump.ino
+
8
−
0
View file @
76e380a4
...
@@ -3,6 +3,7 @@
...
@@ -3,6 +3,7 @@
#include
"temperature.h"
#include
"temperature.h"
#include
"mp3.h"
#include
"mp3.h"
#include
"soundFiles.h"
#include
"soundFiles.h"
#include
"sayNumber.h"
#include
<LiquidCrystal_I2C.h>
#include
<LiquidCrystal_I2C.h>
// LCD display at address 0x27 with 16 columns and 2 rows
// LCD display at address 0x27 with 16 columns and 2 rows
...
@@ -187,6 +188,7 @@ void loop(void) {
...
@@ -187,6 +188,7 @@ void loop(void) {
if
(
checkButton
()
==
LOW
)
{
if
(
checkButton
()
==
LOW
)
{
displayLight
(
true
);
displayLight
(
true
);
<<<<<<<
HEAD
playFileQueue
(
SOUND_EINS
)
playFileQueue
(
SOUND_EINS
)
playFileQueue
(
SOUND_OBEN
);
playFileQueue
(
SOUND_OBEN
);
sayNumber
(
t1up_C
,
nachKommaStellen
);
sayNumber
(
t1up_C
,
nachKommaStellen
);
...
@@ -202,6 +204,12 @@ void loop(void) {
...
@@ -202,6 +204,12 @@ void loop(void) {
playFileQueue
(
SOUND_EINS
)
playFileQueue
(
SOUND_EINS
)
playFileQueue
(
SOUND_OBEN
);
playFileQueue
(
SOUND_OBEN
);
sayNumber
(
t1up_C
,
nachKommaStellen
);
sayNumber
(
t1up_C
,
nachKommaStellen
);
=======
playFileQueue
(
SOUND_TEMPERATURE
);
playFileQueue
(
SOUND_HOCHSTER_WERT
);
playFileQueue
(
SOUND_KOMMA
);
sayNumber
(
14
);
>>>>>>>
728508
c5cadfd2a5e5b3a23185858e4c4d0d5c45
}
else
{
}
else
{
displayLight
(
false
);
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