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.
main.cpp
00001 #include "mbed.h" 00002 #include "PinDetect.h" 00003 00004 //Init leds using PwmOut 00005 PwmOut red(p26); 00006 PwmOut green(p25); 00007 PwmOut blue(p24); 00008 //Init pushbuttons using PinDetect 00009 PinDetect pb1(p21); 00010 PinDetect pb2(p22); 00011 //Init dip switches using DigitalIn 00012 DigitalIn dip1(p15); 00013 DigitalIn dip2(p16); 00014 DigitalIn dip3(p17); 00015 00016 00017 //Increment or decrement the led depending on which button was pressed 00018 void pb1_pressed(void) { 00019 if (dip1 == 1 && red < 1) { red = red + .1; } 00020 if (dip2 == 1 && green < 1) { green = green + .1; } 00021 if (dip3 == 1 && blue < 1) { blue = blue + .1; } 00022 } 00023 void pb2_pressed(void) { 00024 if (dip1 == 1 && red > 0) { red = red - .1; } 00025 if (dip2 == 1 && green > 0) { green = green - .1; } 00026 if (dip3 == 1 && blue > 0) { blue = blue - .1; } 00027 } 00028 00029 int main() { 00030 //Set buttons internal pullup 00031 pb1.mode(PullUp); 00032 pb2.mode(PullUp); 00033 //set for the pressed functions to be called when the button is pressed 00034 pb1.attach_asserted(&pb1_pressed); 00035 pb2.attach_asserted(&pb2_pressed); 00036 //Default the sample freq 00037 pb1.setSampleFrequency(); 00038 pb2.setSampleFrequency(); 00039 //Set switches internal pullup 00040 dip1.mode(PullUp); 00041 dip2.mode(PullUp); 00042 dip3.mode(PullUp); 00043 00044 //Loop forever 00045 while(1) { 00046 if (dip1 == 0) { red = 0; } 00047 if (dip2 == 0) { green = 0; } 00048 if (dip3 == 0) { blue = 0; } 00049 } 00050 } 00051
Generated on Wed Jul 13 2022 08:58:36 by
1.7.2