Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed DebounceIn
main.cpp
- Committer:
- maazshaikh
- Date:
- 2020-02-29
- Revision:
- 1:dd514e5c6507
- Parent:
- 0:ca31694551ed
File content as of revision 1:dd514e5c6507:
#include "mbed.h"
#include "DebounceIn.h"
// must import Cookbook Debounce library into project
// URL: http://mbed.org/users/AjK/libraries/DebounceIn/lky9pc
DigitalOut myled3(p11);
DigitalOut myled4(p12);
DigitalOut myled2(p13);
DebounceIn pb(p8);
DebounceIn pb1(p9);
DebounceIn pb2 (p10);
// SPST Pushbutton count demo using internal PullUp function
// no external PullUp resistor needed
// Pushbutton from P8 to GND.
// Demonstrates need for debounce - will not count more than once per button hit
// This ocuurs on all switches due to mechanical contact bounce
int main()
{
int count=0;
int old_pb=0;
int new_pb;
int old_pb1=0;
int new_pb1;
int order =0;
int old_pb2=0;
int new_pb2;
// Use internal pullup for pushbutton
pb.mode(PullUp);
pb1.mode(PullUp);
// Delay for initial pullup to take effect
wait(.001);
while (1){
myled4=1;
wait(0.5);
myled3=1;
wait(0.5);
myled2=1;
wait(0.5);
myled4=0;
wait(0.5);
myled3=0;
wait(0.5);
myled2=0;
wait(0.5);
while(1) {
new_pb = pb;
new_pb1 = pb1;
new_pb2= pb2;
if ((new_pb==0) && (old_pb==1)) {
count++;
if (order==1){
myled3=1;
order=2;
}
else {
order=0;
myled3=0;
myled4=0;
myled2=0;
wait(3);
break;
}
}
if ((new_pb1==0) && (old_pb1==1)) {
count++;
if (order==0){
myled4=1;
order=1;
}
else {
order=0;
myled3=0;
myled4=0;
wait(3);
break;
}
}
if ((new_pb2==0) && (old_pb2==1)) {
count++;
if (order==2){
myled2=1;
order=0;
wait(3);
myled3=0;
myled4=0;
myled2=0;
wait(3);
break;
}
else {
order=0;
myled3=0;
myled4=0;
myled2=0;
wait(3);
break;
}
}
old_pb = new_pb;
old_pb1 = new_pb1;
old_pb2 = new_pb2;
}
}
}