![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
Ovim programom se upravlja rasvjetom.
Dependencies: Light
main.cpp@1:ac300d8e2d1e, 24 months ago (annotated)
- Committer:
- keepurhealth
- Date:
- Sat Aug 27 12:05:22 2022 +0000
- Revision:
- 1:ac300d8e2d1e
- Parent:
- 0:b41f2bc36513
Popravljeno upravljanje i kontrola V2.0
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
keepurhealth | 0:b41f2bc36513 | 1 | /* mbed Microcontroller Library |
keepurhealth | 0:b41f2bc36513 | 2 | * Copyright (c) 2019 ARM Limited |
keepurhealth | 0:b41f2bc36513 | 3 | * SPDX-License-Identifier: Apache-2.0 |
keepurhealth | 0:b41f2bc36513 | 4 | *Author: Hrvoje Čudina |
keepurhealth | 0:b41f2bc36513 | 5 | */ |
keepurhealth | 0:b41f2bc36513 | 6 | |
keepurhealth | 0:b41f2bc36513 | 7 | #include "mbed.h" // Inicijalizacija mbed biblioteke |
keepurhealth | 0:b41f2bc36513 | 8 | #include "platform/mbed_thread.h" // Inicijalizacija mbed_thread biblioteke |
keepurhealth | 0:b41f2bc36513 | 9 | #include "Light.h" // Inicijalizacija Light biblioteke |
keepurhealth | 0:b41f2bc36513 | 10 | |
keepurhealth | 0:b41f2bc36513 | 11 | InterruptIn button(PA_4); // Inicijalizacija hardverskog prekida |
keepurhealth | 0:b41f2bc36513 | 12 | DigitalOut Yellow(PA_15); // Inicijalizacija digitalnog izlaza Yellow |
keepurhealth | 0:b41f2bc36513 | 13 | Timer debounce; // Inicijalizacija tajmera za debounce |
keepurhealth | 0:b41f2bc36513 | 14 | |
keepurhealth | 0:b41f2bc36513 | 15 | void ON(void); // Inicijalizacija prototipa funkcije |
keepurhealth | 0:b41f2bc36513 | 16 | |
keepurhealth | 0:b41f2bc36513 | 17 | void Turn_OFF(){ // Funkcija za primjenu "Ticker" klase |
keepurhealth | 0:b41f2bc36513 | 18 | if (Yellow == 1){ |
keepurhealth | 0:b41f2bc36513 | 19 | Yellow = 0; |
keepurhealth | 0:b41f2bc36513 | 20 | } |
keepurhealth | 0:b41f2bc36513 | 21 | } |
keepurhealth | 0:b41f2bc36513 | 22 | |
keepurhealth | 0:b41f2bc36513 | 23 | int main() |
keepurhealth | 0:b41f2bc36513 | 24 | { |
keepurhealth | 0:b41f2bc36513 | 25 | Light LED1(PA_13); // Inicijalizacija konstruktora klase Light |
keepurhealth | 0:b41f2bc36513 | 26 | Light LED2(PA_14); // Inicijalizacija konstruktora klase Light |
keepurhealth | 0:b41f2bc36513 | 27 | |
keepurhealth | 0:b41f2bc36513 | 28 | Ticker OFF; // Inicijalizacija konstruktora klase Ticker |
keepurhealth | 0:b41f2bc36513 | 29 | |
keepurhealth | 0:b41f2bc36513 | 30 | DigitalIn Sensor_1(PA_0); // Inicijalizacija digitalnog ulaza |
keepurhealth | 0:b41f2bc36513 | 31 | Sensor_1.mode(PullUp); // Inicijalizacija moda digitalnog ulaza |
keepurhealth | 0:b41f2bc36513 | 32 | |
keepurhealth | 0:b41f2bc36513 | 33 | DigitalIn Sensor_2(PA_1); // Inicijalizacija digitalnog ulaza |
keepurhealth | 0:b41f2bc36513 | 34 | Sensor_2.mode(PullUp); // Inicijalizacija moda digitalnog ulaza |
keepurhealth | 0:b41f2bc36513 | 35 | |
keepurhealth | 0:b41f2bc36513 | 36 | int n = 200; // Definiranje varijable n |
keepurhealth | 0:b41f2bc36513 | 37 | |
keepurhealth | 0:b41f2bc36513 | 38 | debounce.start(); // Početak odbrojavanja tajmera |
keepurhealth | 0:b41f2bc36513 | 39 | button.rise(&ON); // Dodjela funkcije vanjskom prekidu |
keepurhealth | 0:b41f2bc36513 | 40 | OFF.attach(&Turn_OFF, 5.0); // Dodjela funkcije Ticker konstruktoru |
keepurhealth | 0:b41f2bc36513 | 41 | |
keepurhealth | 0:b41f2bc36513 | 42 | while (true) { |
keepurhealth | 0:b41f2bc36513 | 43 | |
keepurhealth | 0:b41f2bc36513 | 44 | if (Sensor_1 == 1){ // Provjera stanja senzora_1 |
keepurhealth | 0:b41f2bc36513 | 45 | LED1.Flash_control(n); |
keepurhealth | 0:b41f2bc36513 | 46 | } |
keepurhealth | 0:b41f2bc36513 | 47 | else { |
keepurhealth | 0:b41f2bc36513 | 48 | LED1.Flash_off(); |
keepurhealth | 0:b41f2bc36513 | 49 | } |
keepurhealth | 0:b41f2bc36513 | 50 | |
keepurhealth | 0:b41f2bc36513 | 51 | if (Sensor_2 == 1){ // Provjera stanja senzora_2 |
keepurhealth | 0:b41f2bc36513 | 52 | LED2.Flash_control(n); |
keepurhealth | 0:b41f2bc36513 | 53 | |
keepurhealth | 0:b41f2bc36513 | 54 | } |
keepurhealth | 0:b41f2bc36513 | 55 | else { |
keepurhealth | 0:b41f2bc36513 | 56 | LED2.Flash_off(); |
keepurhealth | 0:b41f2bc36513 | 57 | } |
keepurhealth | 0:b41f2bc36513 | 58 | |
keepurhealth | 0:b41f2bc36513 | 59 | |
keepurhealth | 0:b41f2bc36513 | 60 | } |
keepurhealth | 0:b41f2bc36513 | 61 | } |
keepurhealth | 0:b41f2bc36513 | 62 | |
keepurhealth | 0:b41f2bc36513 | 63 | void ON(){ // Definirana funkcija za vanjski prekid |
keepurhealth | 0:b41f2bc36513 | 64 | if(debounce.read_ms()>200){ |
keepurhealth | 0:b41f2bc36513 | 65 | Yellow = 1; |
keepurhealth | 0:b41f2bc36513 | 66 | debounce.reset(); |
keepurhealth | 0:b41f2bc36513 | 67 | } |
keepurhealth | 0:b41f2bc36513 | 68 | } |