test

Dependencies:   PWM_LED mbed

Committer:
schoeni_91
Date:
Tue May 03 15:55:55 2016 +0000
Revision:
0:54ed9f9de1fb
led

Who changed what in which revision?

UserRevisionLine numberNew contents of line
schoeni_91 0:54ed9f9de1fb 1 #include "mbed.h"
schoeni_91 0:54ed9f9de1fb 2 #include "C12832_lcd.h"
schoeni_91 0:54ed9f9de1fb 3
schoeni_91 0:54ed9f9de1fb 4 C12832_LCD lcd;
schoeni_91 0:54ed9f9de1fb 5 PwmOut led(LED1);
schoeni_91 0:54ed9f9de1fb 6
schoeni_91 0:54ed9f9de1fb 7 InterruptIn iiDown(p12);
schoeni_91 0:54ed9f9de1fb 8 DigitalIn diDown(p12);
schoeni_91 0:54ed9f9de1fb 9
schoeni_91 0:54ed9f9de1fb 10 InterruptIn iiUp(p15);
schoeni_91 0:54ed9f9de1fb 11 DigitalIn diUp(p15);
schoeni_91 0:54ed9f9de1fb 12
schoeni_91 0:54ed9f9de1fb 13 float brightness=0.0;
schoeni_91 0:54ed9f9de1fb 14
schoeni_91 0:54ed9f9de1fb 15 uint8_t debounce(DigitalIn myIn)
schoeni_91 0:54ed9f9de1fb 16 {
schoeni_91 0:54ed9f9de1fb 17 #define LEVEL_CHECKS 132
schoeni_91 0:54ed9f9de1fb 18 #define MAX_LOOPS 36 // stoppt das Überprüfen des Prellen nach max. MAX_LOOPS Durchläufen
schoeni_91 0:54ed9f9de1fb 19 unsigned char port_buffer;
schoeni_91 0:54ed9f9de1fb 20 unsigned char debounceCounter = 0;
schoeni_91 0:54ed9f9de1fb 21 uint8_t loopCounter = 0;
schoeni_91 0:54ed9f9de1fb 22
schoeni_91 0:54ed9f9de1fb 23 do {
schoeni_91 0:54ed9f9de1fb 24 port_buffer = myIn;
schoeni_91 0:54ed9f9de1fb 25 wait_us(500);
schoeni_91 0:54ed9f9de1fb 26 loopCounter++;
schoeni_91 0:54ed9f9de1fb 27 if(myIn == port_buffer)
schoeni_91 0:54ed9f9de1fb 28 debounceCounter++; // mindestens 'LEVEL_CHECKS' Abtastungen in Folge: gleicher Pegel
schoeni_91 0:54ed9f9de1fb 29 else
schoeni_91 0:54ed9f9de1fb 30 debounceCounter = 0;
schoeni_91 0:54ed9f9de1fb 31 } while ((debounceCounter <= LEVEL_CHECKS) && (loopCounter <= MAX_LOOPS));
schoeni_91 0:54ed9f9de1fb 32 return loopCounter;
schoeni_91 0:54ed9f9de1fb 33 }
schoeni_91 0:54ed9f9de1fb 34
schoeni_91 0:54ed9f9de1fb 35 void bightnessUP()
schoeni_91 0:54ed9f9de1fb 36 {
schoeni_91 0:54ed9f9de1fb 37 debounce(diUp);
schoeni_91 0:54ed9f9de1fb 38 brightness += 0.1; led = brightness;
schoeni_91 0:54ed9f9de1fb 39 }
schoeni_91 0:54ed9f9de1fb 40
schoeni_91 0:54ed9f9de1fb 41 void bightnessDOWN()
schoeni_91 0:54ed9f9de1fb 42 {
schoeni_91 0:54ed9f9de1fb 43 debounce(diDown);
schoeni_91 0:54ed9f9de1fb 44 brightness -= 0.1; led = brightness;
schoeni_91 0:54ed9f9de1fb 45 }
schoeni_91 0:54ed9f9de1fb 46
schoeni_91 0:54ed9f9de1fb 47 void init ()
schoeni_91 0:54ed9f9de1fb 48 {
schoeni_91 0:54ed9f9de1fb 49 iiUp.rise(&bightnessUP);
schoeni_91 0:54ed9f9de1fb 50 iiDown.rise(&bightnessDOWN);
schoeni_91 0:54ed9f9de1fb 51
schoeni_91 0:54ed9f9de1fb 52 }
schoeni_91 0:54ed9f9de1fb 53
schoeni_91 0:54ed9f9de1fb 54 void abschalten()
schoeni_91 0:54ed9f9de1fb 55 {
schoeni_91 0:54ed9f9de1fb 56 lcd.cls();
schoeni_91 0:54ed9f9de1fb 57 lcd.locate(0,0);
schoeni_91 0:54ed9f9de1fb 58 lcd.printf("SNT abschalten !!");
schoeni_91 0:54ed9f9de1fb 59
schoeni_91 0:54ed9f9de1fb 60 }
schoeni_91 0:54ed9f9de1fb 61 int main()
schoeni_91 0:54ed9f9de1fb 62 {
schoeni_91 0:54ed9f9de1fb 63
schoeni_91 0:54ed9f9de1fb 64
schoeni_91 0:54ed9f9de1fb 65
schoeni_91 0:54ed9f9de1fb 66 while(true) {
schoeni_91 0:54ed9f9de1fb 67 init();
schoeni_91 0:54ed9f9de1fb 68 if (brightness>=0.8) {
schoeni_91 0:54ed9f9de1fb 69 abschalten ();
schoeni_91 0:54ed9f9de1fb 70 }
schoeni_91 0:54ed9f9de1fb 71 if (brightness<=0.8) {
schoeni_91 0:54ed9f9de1fb 72 lcd.cls();
schoeni_91 0:54ed9f9de1fb 73 }
schoeni_91 0:54ed9f9de1fb 74 }
schoeni_91 0:54ed9f9de1fb 75 }
schoeni_91 0:54ed9f9de1fb 76
schoeni_91 0:54ed9f9de1fb 77
schoeni_91 0:54ed9f9de1fb 78
schoeni_91 0:54ed9f9de1fb 79