Commit cd1778e2 authored by Šmelko Adam Mgr.'s avatar Šmelko Adam Mgr.
Browse files

Add recording.

parent 417ca913
//////////////////////////////////////////
#include "funshield.h"
constexpr int leds[] = { led1_pin, led2_pin, led3_pin, led4_pin };
constexpr int ledCount = sizeof(leds) / sizeof(leds[0]);
constexpr int buttons[] = { button1_pin, button2_pin, button3_pin };
constexpr int buttonCount = sizeof(buttons) / sizeof(buttons[0]);
void setup() {
// put your setup code here, to run once:
for (int led : leds) {
pinMode(led, OUTPUT);
digitalWrite(led, OFF);
}
for (int button : buttons) {
pinMode(button, INPUT);
}
}
void loop() {
// put your main code here, to run repeatedly:
for (int i =0; i< buttonCount; i++){
bool pressed = !digitalRead(buttons[i]);
digitalWrite(leds[i], pressed ? ON : OFF);
}
}
//////////////////////////////////////////
#include "funshield.h"
constexpr int leds[] = { led1_pin, led2_pin, led3_pin, led4_pin };
constexpr int ledCount = sizeof(leds) / sizeof(leds[0]);
constexpr int buttons[] = { button1_pin, button2_pin, button3_pin };
constexpr int buttonCount = sizeof(buttons) / sizeof(buttons[0]);
void setup() {
// put your setup code here, to run once:
for (auto led : leds) {
pinMode(led, OUTPUT);
digitalWrite(led, OFF);
}
for (auto button : buttons) {
pinMode(button, INPUT);
}
}
class LedState
{
public:
enum InnerStates { BEING_PRESSED, NOT_BEEING_PRESSED };
LedState(int pin) {
pin_ = pin;
}
void react(bool buttonPressed)
{
if (!buttonPressed) {
state_ = NOT_BEEING_PRESSED;
return;
}
if (buttonPressed && state_ == BEING_PRESSED)
return;
state_ = BEING_PRESSED;
is_on_ = !is_on_;
digitalWrite(pin_, is_on_ ? ON : OFF);
}
private:
bool is_on_ = false;
InnerStates state_ = NOT_BEEING_PRESSED;
int pin_;
};
LedState ledStates[] { LedState(led1_pin), LedState(led2_pin), LedState(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);
}
}
//////////////REFERENCE/////////////////
#include <iostream>
class Test
{
public:
int x = 1;
};
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!!!!!
}
\ No newline at end of file
......@@ -596,7 +596,7 @@ $(document).ready(function(){
<td class="right">31.3.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/3efe7597-5576-4644-9eaf-b0b0473fda79">Recorded lab</a></td>
</tr>
<tr>
<td class="right">6.4.2021</td>
......
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