![](/media/cache/profiles/sddefault.jpg.50x50_q85.jpg)
samo jak gas
main.cpp@0:14719bc34055, 2021-11-13 (annotated)
- Committer:
- makotolagano
- Date:
- Sat Nov 13 07:05:29 2021 +0000
- Revision:
- 0:14719bc34055
najjaci gas;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
makotolagano | 0:14719bc34055 | 1 | /* |
makotolagano | 0:14719bc34055 | 2 | |
makotolagano | 0:14719bc34055 | 3 | Lazar Dobric 11/12/2021 23:12 EST |
makotolagano | 0:14719bc34055 | 4 | |
makotolagano | 0:14719bc34055 | 5 | */ |
makotolagano | 0:14719bc34055 | 6 | |
makotolagano | 0:14719bc34055 | 7 | |
makotolagano | 0:14719bc34055 | 8 | // importing libraries |
makotolagano | 0:14719bc34055 | 9 | #include "mbed.h" |
makotolagano | 0:14719bc34055 | 10 | |
makotolagano | 0:14719bc34055 | 11 | |
makotolagano | 0:14719bc34055 | 12 | // macros |
makotolagano | 0:14719bc34055 | 13 | #define VOLTAGE_SCALER 3.3f |
makotolagano | 0:14719bc34055 | 14 | #define VOLTAGE_LIMIT 2.7f |
makotolagano | 0:14719bc34055 | 15 | #define PWM_PERIOD_MS 1 |
makotolagano | 0:14719bc34055 | 16 | #define BUZZER_HIGH 0.9f |
makotolagano | 0:14719bc34055 | 17 | #define BUZZER_LOW 0 |
makotolagano | 0:14719bc34055 | 18 | |
makotolagano | 0:14719bc34055 | 19 | |
makotolagano | 0:14719bc34055 | 20 | AnalogIn pot2(PA_1); |
makotolagano | 0:14719bc34055 | 21 | PwmOut buzzer(PA_11); |
makotolagano | 0:14719bc34055 | 22 | InterruptIn sw1(PC_9); |
makotolagano | 0:14719bc34055 | 23 | |
makotolagano | 0:14719bc34055 | 24 | // global |
makotolagano | 0:14719bc34055 | 25 | static char buzzing = 0; |
makotolagano | 0:14719bc34055 | 26 | |
makotolagano | 0:14719bc34055 | 27 | // declarations |
makotolagano | 0:14719bc34055 | 28 | void ISR_sw1(void); |
makotolagano | 0:14719bc34055 | 29 | |
makotolagano | 0:14719bc34055 | 30 | int main() |
makotolagano | 0:14719bc34055 | 31 | { |
makotolagano | 0:14719bc34055 | 32 | |
makotolagano | 0:14719bc34055 | 33 | buzzer.period_ms(PWM_PERIOD_MS); |
makotolagano | 0:14719bc34055 | 34 | buzzer.write(BUZZER_LOW); |
makotolagano | 0:14719bc34055 | 35 | sw1.fall(&ISR_sw1); |
makotolagano | 0:14719bc34055 | 36 | |
makotolagano | 0:14719bc34055 | 37 | while(true) |
makotolagano | 0:14719bc34055 | 38 | { |
makotolagano | 0:14719bc34055 | 39 | if(pot2.read()*VOLTAGE_SCALER >= VOLTAGE_LIMIT) |
makotolagano | 0:14719bc34055 | 40 | { |
makotolagano | 0:14719bc34055 | 41 | if (!buzzing) |
makotolagano | 0:14719bc34055 | 42 | { |
makotolagano | 0:14719bc34055 | 43 | buzzer.write(BUZZER_HIGH); |
makotolagano | 0:14719bc34055 | 44 | buzzing = 1; |
makotolagano | 0:14719bc34055 | 45 | } |
makotolagano | 0:14719bc34055 | 46 | } |
makotolagano | 0:14719bc34055 | 47 | else |
makotolagano | 0:14719bc34055 | 48 | { |
makotolagano | 0:14719bc34055 | 49 | buzzing = 0; |
makotolagano | 0:14719bc34055 | 50 | } |
makotolagano | 0:14719bc34055 | 51 | |
makotolagano | 0:14719bc34055 | 52 | |
makotolagano | 0:14719bc34055 | 53 | } |
makotolagano | 0:14719bc34055 | 54 | |
makotolagano | 0:14719bc34055 | 55 | } |
makotolagano | 0:14719bc34055 | 56 | |
makotolagano | 0:14719bc34055 | 57 | // Interrupt Service Routine |
makotolagano | 0:14719bc34055 | 58 | void ISR_sw1(void) |
makotolagano | 0:14719bc34055 | 59 | { |
makotolagano | 0:14719bc34055 | 60 | buzzer.write(BUZZER_LOW); |
makotolagano | 0:14719bc34055 | 61 | buzzing = 0; |
makotolagano | 0:14719bc34055 | 62 | |
makotolagano | 0:14719bc34055 | 63 | } |
makotolagano | 0:14719bc34055 | 64 | |
makotolagano | 0:14719bc34055 | 65 |