Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
teaching
nswi170
web
Commits
532c1569
Commit
532c1569
authored
Apr 14, 2021
by
Šmelko Adam Mgr.
Browse files
lab04.
parent
8c79bb79
Changes
4
Hide whitespace changes
Inline
Side-by-side
download/smelko/cvicenie4.txt
0 → 100644
View file @
532c1569
#include "funshield.h"
constexpr int digit_positions = 4;
void writeGlyphBitmask( byte glyph, byte pos_bitmask) {
digitalWrite( latch_pin, LOW);
shiftOut( data_pin, clock_pin, MSBFIRST, glyph);
shiftOut( data_pin, clock_pin, MSBFIRST, pos_bitmask);
digitalWrite( latch_pin, HIGH);
}
void writeGlyphR(byte glyph, int pos)
{
writeGlyphBitmask(glyph, digit_muxpos[digit_positions - pos - 1]);
}
void writeGlyphL(byte glyph, int pos)
{
writeGlyphBitmask(glyph, digit_muxpos[pos]);
}
void writeDigit(int n, int pos)
{
writeGlyphR(digits[n], pos);
}
enum LedState {PRESSED, RELEASED};
class ButtonPresser
{
public:
ButtonPresser(int pin) {
pin_ = pin;
}
bool pressedOnce(bool button_pressed)
{
if (button_pressed == false) {
prev_state_ = RELEASED;
return false;
}
if (prev_state_ == PRESSED && button_pressed)
return false;
prev_state_ = PRESSED;
return true;
}
private:
LedState prev_state_ = RELEASED;
int pin_;
};
void setup() {
pinMode(latch_pin, OUTPUT);
pinMode(data_pin, OUTPUT);
pinMode(clock_pin, OUTPUT);
}
constexpr int buttons[] = { button1_pin, button2_pin, button3_pin };
ButtonPresser pressers[] { ButtonPresser(button1_pin), ButtonPresser(button2_pin), ButtonPresser(button3_pin) };
int citac = 0;
int pozicia = 0;
void loop() {
// put your main code here, to run repeatedly:
if ( pressers[0].pressedOnce(!digitalRead(buttons[0])))
citac += 1;
if (pressers[1].pressedOnce(!digitalRead(buttons[1])))
citac += 9;
if (pressers[2].pressedOnce(!digitalRead(buttons[2])))
pozicia +=1;
pozicia %=4;
citac %= 10;
writeDigit(citac, pozicia);
}
download/smelko/nswi170-lab04-as.pdf
View file @
532c1569
No preview for this file type
index.html
View file @
532c1569
...
...
@@ -644,7 +644,7 @@ $(document).ready(function(){
<td
class=
"right"
>
14.4.2021
</td>
<td>
934 5196 8778
</td>
<td><a
class=
"extern"
href=
"https://cesnet.zoom.us/j/93451968778"
>
Join the lab - Šmelko
</a></td>
<td>
Recorded lab
</td>
<td>
<a
class=
"extern"
href=
"https://web.microsoftstream.com/video/c8f464e7-84fc-4259-b5f3-ce26d18813c7"
>
Recorded lab
</
a></
td>
</tr>
<tr>
<td
class=
"right"
>
20.4.2021
</td>
...
...
smelko.html
View file @
532c1569
...
...
@@ -87,10 +87,10 @@
<span>
lab04
</span>
</a>
</td>
<td>
<!--<a href="http://ulita.ms.mff.cuni.cz/~zavoral/nswi170/ard-53.mp4">4.4</a>
<a href="http://ulita.ms.mff.cuni.cz/~zavoral/nswi170/ard-54.mp4">4.5</a
>
Čtení ze sériové linky je pro teď nepovinné, bude se ale hodit pro pozdější úlohy
--
>
<td>
<a
href=
"download/smelko/cvicenie4.txt"
>
poznámky k 4. cvičeniu
</a
>
</td>
</tr>
<tr>
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment