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 // 4180 Lab 1, Part 2 00002 // Gregory Lanier 00003 00004 #include "mbed.h" 00005 #include "PinDetect.h" 00006 00007 /* 00008 This program lights up a built in LED and enables dimming with two push buttons. 00009 */ 00010 00011 // Global Vars 00012 float brightness = 0.5f; // Initial brightness 1/2 power 00013 00014 // I/O 00015 PinDetect dimButton(p8); // Make LED dimmer with p8 button 00016 PinDetect brightButton(p9); // Make LED brighter with p9 button 00017 PwmOut mbedLED(LED1); // LED1 built into Mbed 00018 00019 // Dim Callback 00020 void dim_callback(void) { 00021 brightness -= 0.1f; 00022 } 00023 00024 // Brighten Callback 00025 void bright_callback(void) { 00026 brightness += 0.1f; 00027 } 00028 00029 int main() 00030 { 00031 // Button Mode Set 00032 dimButton.mode(PullUp); 00033 brightButton.mode(PullUp); 00034 wait(0.01); 00035 00036 // Setuo button callbacks 00037 dimButton.attach_deasserted(&dim_callback); 00038 brightButton.attach_deasserted(&bright_callback); 00039 00040 // Start sampling button inputs using interrupts 00041 dimButton.setSampleFrequency(); 00042 brightButton.setSampleFrequency(); 00043 00044 // Logic Loop 00045 while(1) { 00046 mbedLED = brightness; // Update brightness 00047 } 00048 }
Generated on Wed Sep 20 2023 09:27:26 by
1.7.2