Commit 4b2a0028 authored by Jakub Yaghob's avatar Jakub Yaghob
Browse files

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

parents b58fb7d1 4e875559
......@@ -45,70 +45,63 @@ void setup() {
}
}
class LedState
enum LedState {PRESSED, RELEASED};
class LedSwitcher
{
public:
enum InnerStates { BEING_PRESSED, NOT_BEEING_PRESSED };
LedState(int pin) {
LedSwitcher(int pin) {
pin_ = pin;
}
void react(bool buttonPressed)
void switchOnOff(bool button_pressed)
{
if (!buttonPressed) {
state_ = NOT_BEEING_PRESSED;
if (button_pressed == false) {
prev_state_ = RELEASED;
return;
}
if (buttonPressed && state_ == BEING_PRESSED)
if (prev_state_ == PRESSED && button_pressed)
return;
state_ = BEING_PRESSED;
prev_state_ = PRESSED;
is_on_ = !is_on_;
digitalWrite(pin_, is_on_ ? ON : OFF);
}
private:
bool is_on_ = false;
InnerStates state_ = NOT_BEEING_PRESSED;
LedState prev_state_ = RELEASED;
int pin_;
};
LedState ledStates[] { LedState(led1_pin), LedState(led2_pin), LedState(led3_pin) };
LedSwitcher switchers[] { LedSwitcher(led1_pin), LedSwitcher(led2_pin), LedSwitcher(led3_pin) };
void loop() {
// put your main code here, to run repeatedly:
for (int i = 0; i < buttonCount; i++) {
bool pressed = !digitalRead(buttons[i]);
ledStates[i].react(pressed);
switchers[i].switchOnOff(pressed);
}
}
//////////////REFERENCE/////////////////
#include <iostream>
class Test
class X
{
public:
int x = 1;
void zdvihniCitac(int& citac) // <<<<< aha ampersand
{
citac++;
}
};
void fNOREF(Test test)
{
test.x = 2;
}
void fREF(Test& test)
{
test.x = 2;
}
int main()
{
Test test;
test.x = 8;
fNOREF(test);
std::cout << "Test::x is: "<<test.x << std::endl; // prints 8!!!!!
fREF(test);
std::cout << "Test::x is: "<<test.x << std::endl; // prints 2!!!!!
X object;
int citac = 4;
object.zdvihniCitac(citac);
std::cout << citac << std::endl; // citac sa zdvihne len ked je pri parametri metody & !!!
}
\ No newline at end of file
......@@ -399,6 +399,14 @@ $(document).ready(function(){
<td><code>class Foo { static void foo() ... }</code></td>
<td>Static methods do not work in ReCodEx, use plain old C functions instead.</td>
</tr>
<tr>
<td>Initialization</td>
<td><code>class Button { </code><br>
<code> Button() { pinMode( b[0], INPUT); } </code><br>
<code>};</code></td>
<td>Emulator (Arduino) initilization (e.g., pinMode) <b>MUST</b> be called in setup.
Early emulator initialization (e.g., in a constructor of a global object) causes a signal and your program is terminated.</td>
</tr>
</table>
......@@ -624,7 +632,7 @@ $(document).ready(function(){
<td class="right">7.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/63d2b687-f5dd-49d1-a82f-6361c01df730">Recorded lab</a></td>
</tr>
<tr>
<td class="right">13.4.2021</td>
......
......@@ -100,10 +100,10 @@ $(document).ready(function(){
<a class="extern" href="https://youtu.be/Nf6J54v5oD4">visualization of Task 6</a>
</td>
<td>
<a class="extern" href="https://web.microsoftstream.com/video/e8bbb791-1e10-4729-9baa-287492eefebc">recording</a>
</td>
<td>
<a class="extern" href="https://recodex.mff.cuni.cz/app/assignment/0a97fde0-979e-11eb-a1a9-005056ad4f31">assignment</a>
</td>
</tr>
<tr>
......
......@@ -46,22 +46,20 @@
<td>2.</td>
<td>Arduino, LED</td>
<td>2.1-2.5</td>
<td>Srdíčkové úlohy/rozšíření jsou bonusové (nepovinné, pro zájemce, ...)</td>
<td>srdíčkové úlohy/rozšíření jsou bonusové (nepovinné, pro zájemce, ...)</td>
</tr>
<tr>
<td>3.</td>
<td>Tlačítka</td>
<td>3.4, 3.5</td>
<td>Funkčnost úloh na <a href="https://web.microsoftstream.com/group/9607af45-65ca-4046-b9d1-6b1100451670?view=videos">Streamu</a></td>
<td>funkčnost úloh na <a href="https://web.microsoftstream.com/group/9607af45-65ca-4046-b9d1-6b1100451670?view=videos">Streamu</a></td>
</tr>
<tr>
<td>4.</td>
<td>Segmentový displej, sériová linka</td>
<td></td>
<td><!--<a href="http://ulita.ms.mff.cuni.cz/~zavoral/nswi170/ard-53.mp4">4.4</a>
&nbsp;&nbsp;<a href="http://ulita.ms.mff.cuni.cz/~zavoral/nswi170/ard-54.mp4">4.5</a>
&nbsp;&nbsp;Čtení ze sériové linky je pro teď nepovinné, bude se ale hodit pro pozdější úlohy
-->
<td>4.3, 4.4</td>
<td>použít funkce z 4.2 a 4.1
<!-- <a href="ard-44.mp4">4.4</a>nbsp;&nbsp; <a href="ard-45.mp4">4.5</a> -->
</td>
</tr>
<tr>
......
Supports Markdown
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