Switch bounce demonstration

Committer:
reedas
Date:
Tue Nov 12 10:03:21 2019 +0000
Revision:
0:2b3584252caf
CITY1082 example code

Who changed what in which revision?

UserRevisionLine numberNew contents of line
reedas 0:2b3584252caf 1 /* mbed Microcontroller Library
reedas 0:2b3584252caf 2 * Copyright (c) 2019 ARM Limited
reedas 0:2b3584252caf 3 * SPDX-License-Identifier: Apache-2.0
reedas 0:2b3584252caf 4 */
reedas 0:2b3584252caf 5
reedas 0:2b3584252caf 6 #include "mbed.h"
reedas 0:2b3584252caf 7 #include "platform/mbed_thread.h"
reedas 0:2b3584252caf 8
reedas 0:2b3584252caf 9
reedas 0:2b3584252caf 10 // Blinking rate in milliseconds
reedas 0:2b3584252caf 11 #define BLINKING_RATE_MS 500
reedas 0:2b3584252caf 12
reedas 0:2b3584252caf 13
reedas 0:2b3584252caf 14 int main()
reedas 0:2b3584252caf 15 {
reedas 0:2b3584252caf 16 // Initialise the digital pin LED1 as an output
reedas 0:2b3584252caf 17 DigitalOut led(LED1);
reedas 0:2b3584252caf 18 DigitalIn sw2(SWITCH2, PullUp);
reedas 0:2b3584252caf 19 int count = 0;
reedas 0:2b3584252caf 20
reedas 0:2b3584252caf 21 while (true) {
reedas 0:2b3584252caf 22 if (sw2 == 1) {
reedas 0:2b3584252caf 23 while ( sw2 == 1) {
reedas 0:2b3584252caf 24 count = count;
reedas 0:2b3584252caf 25 }
reedas 0:2b3584252caf 26
reedas 0:2b3584252caf 27 led = !led;
reedas 0:2b3584252caf 28 count = count + 1;
reedas 0:2b3584252caf 29 printf("Count is %d\r\n", count);
reedas 0:2b3584252caf 30 }
reedas 0:2b3584252caf 31 }
reedas 0:2b3584252caf 32 }