Commit aff3bb44 authored by Zavoral Filip RNDr. Ph.D.'s avatar Zavoral Filip RNDr. Ph.D.
Browse files

Merge branch 'master' of https://gitlab.mff.cuni.cz/teaching/nswi170/web into master

parents 6c1d95a9 b6bf9420
#include "funshield.h"
constexpr int digit_positions = sizeof(digit_muxpos) / sizeof(digit_muxpos[0]);
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);
}
void setup() {
pinMode(latch_pin, OUTPUT);
pinMode(data_pin, OUTPUT);
pinMode(clock_pin, OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
writeDigit(1, 0);
writeDigit(2, 1);
writeDigit(3, 2);
writeDigit(4, 3);
delay(5); //ODKOMENTUJ A VYSKUSAJ ZNOVA
}
################################################################
#include "funshield.h"
constexpr int digit_positions = sizeof(digit_muxpos) / sizeof(digit_muxpos[0]);
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_;
};
int mocniny[] { 1, 10, 100, 1000 };
class Display
{
public:
void set(int cislo)
{
cislo_ = cislo;
}
void loop()
{
int cislica = (cislo_ / mocniny[pozicia_]) % 10;
writeDigit(cislica, pozicia_);
pozicia_++;
pozicia_ %= 4;
}
private:
int cislo_;
int pozicia_ = 0;
};
void setup() {
pinMode(latch_pin, OUTPUT);
pinMode(data_pin, OUTPUT);
pinMode(clock_pin, OUTPUT);
}
constexpr int buttons[] = { button1_pin, button2_pin};
ButtonPresser pressers[] { ButtonPresser(button1_pin), ButtonPresser(button2_pin)};
Display d;
int citac = 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 -= 1;
citac = (citac + 10000) % 10000;
d.set(citac);
d.loop();
//delay(10); ODKOMENTUJ A VYSKUSAJ ZNOVA
}
\ No newline at end of file
......@@ -672,13 +672,13 @@ $(document).ready(function(){
<td class="right">27.4.2021</td>
<td>915 2445 5145</td>
<td><a class="extern" href="https://cesnet.zoom.us/j/91524455145">Join the lecture - Yaghob</a></td>
<td>Recorded lecture</td>
<td><a class="extern" href="https://web.microsoftstream.com/video/f9da25dc-ac2f-4e45-bedc-a6844804aeb3">Recorded lecture</a></td>
</tr>
<tr>
<td class="right">28.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/af0de5de-5270-441e-bfb4-59d9f16db224">Recorded lecture</a></td>
</tr>
<tr>
<td class="right">4.5.2021</td>
......
......@@ -96,13 +96,16 @@
<tr>
<td>5.</td>
<td>Segmentový displej - multiplex</td>
<td></td>
<td><!--Časový multiplex
&nbsp;&nbsp;<a href="http://ulita.ms.mff.cuni.cz/~zavoral/nswi170/ard-63.mp4">5.3</a>
&nbsp;&nbsp;<a href="http://ulita.ms.mff.cuni.cz/~zavoral/nswi170/ard-64.mp4">5.4</a>
&nbsp;&nbsp;<a href="http://ulita.ms.mff.cuni.cz/~zavoral/nswi170/ard-65.mp4">5.5</a>
&nbsp;&nbsp;<a href="http://ulita.ms.mff.cuni.cz/~zavoral/nswi170/ard-65b.mp4">5.5b</a>
-->
<td>
<a class="file_link" href="download/smelko/nswi170-lab05-as.pdf">
<img src="pic/pdf-icon.png" alt="PDF File Icon">
<span>lab05</span>
</a>
</td>
<td>
<a href="download/smelko/cvicenie5.txt">
poznámky k 5. cvičeniu
</a>
</td>
</tr>
<tr>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment