Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
dmpada
/
eriala-2024
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
6fe8c0a5
authored
Oct 08, 2024
by
Risto Heinsar
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added lab 2 demo codes
parent
23823f64
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
215 additions
and
0 deletions
lab2/lab2_demo_btn_read/lab2_demo_btn_read.ino
lab2/lab2_demo_const/lab2_demo_const.ino
lab2/lab2_demo_macro/lab2_demo_macro.ino
lab2/lab2_demo_potentiometer/lab2_demo_potentiometer.ino
lab2/lab2_demo_pwm_fade/lab2_demo_pwm_fade.ino
lab2/lab2_demo_states_conditional_led/lab2_demo_states_conditional_led.ino
lab2/lab2_demo_states_led/lab2_demo_states_led.ino
lab2/lab2_demo_states_tristate_led/lab2_demo_states_tristate_led.ino
lab2/lab2_demo_btn_read/lab2_demo_btn_read.ino
0 → 100644
View file @
6fe8c0a5
#define BTN_PIN 3
const
int
tickDelay
=
100
;
void
setup
()
{
// Alustame jadaühenduse
Serial
.
begin
(
9600
);
// Määrame nupu sisendiks
pinMode
(
BTN_PIN
,
INPUT
);
}
void
loop
()
{
// Loeme nupu oleku
bool
btnState
=
digitalRead
(
BTN_PIN
);
// Saadame nupu oleku üle jadaühenduse
Serial
.
print
(
"btn:"
);
Serial
.
println
(
btnState
);
delay
(
tickDelay
);
}
\ No newline at end of file
lab2/lab2_demo_const/lab2_demo_const.ino
0 → 100644
View file @
6fe8c0a5
// Konstant tüüpi muutuja deklareerimine
const
int
leftLedPin
=
7
;
void
setup
()
{
// Seadistame parempoolse LEDi väljundiks
pinMode
(
leftLedPin
,
OUTPUT
);
}
void
loop
()
{
// Lülitame LEDi sisse 500 ms
digitalWrite
(
leftLedPin
,
HIGH
);
delay
(
500
);
// Seejärel lülitame LEDi välja ning ootame veel 500 ms
digitalWrite
(
leftLedPin
,
LOW
);
delay
(
500
);
}
\ No newline at end of file
lab2/lab2_demo_macro/lab2_demo_macro.ino
0 → 100644
View file @
6fe8c0a5
// Makro defineerimine
#define LED_LEFT_PIN 7
void
setup
()
{
// Seadistame parempoolse LEDi väljundiks
pinMode
(
LED_LEFT_PIN
,
OUTPUT
);
}
void
loop
()
{
// Lülitame LEDi sisse 500 ms
digitalWrite
(
LED_LEFT_PIN
,
HIGH
);
delay
(
500
);
// Seejärel lülitame LEDi välja ning ootame veel 500 ms
digitalWrite
(
LED_LEFT_PIN
,
LOW
);
delay
(
500
);
}
\ No newline at end of file
lab2/lab2_demo_potentiometer/lab2_demo_potentiometer.ino
0 → 100644
View file @
6fe8c0a5
// Potentsiomeeter kasutab analoogviiku
#define POT_PIN A2
// Uuendus iga 200 ms tagant
const
int
tickDelay
=
200
;
void
setup
()
{
Serial
.
begin
(
9600
);
}
void
loop
()
{
// Loeme potentsiomeetri väärtuse ja edastame üle jadaühenduse
int
potVal
=
analogRead
(
POT_PIN
);
Serial
.
println
(
potVal
);
delay
(
tickDelay
);
}
\ No newline at end of file
lab2/lab2_demo_pwm_fade/lab2_demo_pwm_fade.ino
0 → 100644
View file @
6fe8c0a5
#define LED_PIN 3
#define MIN_BRIGHTNESS 20
#define MAX_BRIGHTNESS 90
const
int
tickDelay
=
20
;
int
brightness
=
MIN_BRIGHTNESS
;
int
brightnessShift
=
1
;
void
setup
()
{
}
void
loop
()
{
// Muudame eredust
brightness
+=
brightnessShift
;
// Jõudes valgustugevuse piirideni, muudame ereduse muutumise suunda
if
(
brightness
>=
MAX_BRIGHTNESS
||
brightness
<=
MIN_BRIGHTNESS
)
{
brightnessShift
=
-
brightnessShift
;
}
// Kasutades PWMi, uuendame LEDi eredust
analogWrite
(
LED_PIN
,
brightness
);
delay
(
tickDelay
);
}
\ No newline at end of file
lab2/lab2_demo_states_conditional_led/lab2_demo_states_conditional_led.ino
0 → 100644
View file @
6fe8c0a5
#define LED_LEFT_PIN 7
const
int
tickDelay
=
500
;
bool
ledState
=
true
;
void
setup
()
{
// Seadistame parempoolse LEDi väljundiks
pinMode
(
LED_LEFT_PIN
,
OUTPUT
);
}
void
loop
()
{
// Anname LEDile uue oleku
digitalWrite
(
LED_LEFT_PIN
,
ledState
);
// Kontrollime, kas siide ühest olekust teise on lubatud
if
(
btnState
)
{
// Teostame siirde
ledState
=
!
ledState
;
}
delay
(
tickDelay
);
}
\ No newline at end of file
lab2/lab2_demo_states_led/lab2_demo_states_led.ino
0 → 100644
View file @
6fe8c0a5
#define LED_LEFT_PIN 7
const
int
tickDelay
=
500
;
bool
ledState
=
true
;
void
setup
()
{
// Seadistame parempoolse LEDi väljundiks
pinMode
(
LED_LEFT_PIN
,
OUTPUT
);
}
void
loop
()
{
// Anname LEDile uue oleku
digitalWrite
(
LED_LEFT_PIN
,
ledState
);
// Muudame LEDi olekut järgmiseks tsükliks
ledState
=
!
ledState
;
delay
(
tickDelay
);
}
\ No newline at end of file
lab2/lab2_demo_states_tristate_led/lab2_demo_states_tristate_led.ino
0 → 100644
View file @
6fe8c0a5
// LEDi viigu defineerimine
#define LED_PIN 3
// Kodeeritud süsteemi olekud
#define STATE_LED_OFF 0
#define STATE_LED_HALF_POWER 1
#define STATE_LED_FULL_POWER 2
// PWM täitetegurid
#define LED_PWN_OFF 0
#define LED_PWM_HALF 127
#define LED_PWM_FULL 255
const
int
tickDelay
=
500
;
int
ledState
=
STATE_LED_OFF
;
int
brightness
=
LED_PWN_OFF
;
void
setup
()
{
}
void
loop
()
{
// Leiame oleku põhjal PWM signaali täiteteguri
switch
(
ledState
)
{
case
STATE_LED_OFF
:
brightness
=
LED_PWN_OFF
;
break
;
case
STATE_LED_HALF_POWER
:
brightness
=
LED_PWM_HALF
;
break
;
case
STATE_LED_FULL_POWER
:
brightness
=
LED_PWM_FULL
;
break
;
default:
brightness
=
LED_PWN_OFF
;
}
// Kasutades PWMi, uuendame LEDi eredust
analogWrite
(
LED_PIN
,
brightness
);
// Siire järgmisse olekusse
ledState
=
(
ledState
+
1
)
%
3
;
delay
(
tickDelay
);
}
\ No newline at end of file
Write
Preview
Markdown
is supported
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