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
main.cpp
00001 #include "mbed.h" 00002 00003 //Global PWM object 00004 PwmOut pwmRed(D6); 00005 00006 int T = 100; //100uS 00007 volatile int Tmark = 0; //0us 00008 volatile int delta = 1; //1us 00009 00010 //Timer 00011 Ticker t; 00012 00013 //Function prototype 00014 void doTwinkle(); 00015 00016 int main() { 00017 00018 //Initial PWM state 00019 pwmRed.period_us(T); 00020 pwmRed.pulsewidth_us(Tmark); 00021 00022 //Start timer 00023 t.attach(doTwinkle, 0.01); 00024 00025 while(1) { 00026 sleep(); 00027 00028 //Update PWM 00029 pwmRed.pulsewidth_us(Tmark); 00030 00031 //printf("Tmark = %d\n", Tmark); //Debug 00032 } 00033 } 00034 00035 //ISR for Timer 00036 void doTwinkle() 00037 { 00038 //Update mark time 00039 Tmark += delta; 00040 00041 //Check bounds - and swap direction 00042 if ((Tmark >= 99) || (Tmark <= 0)) { 00043 delta = -delta; 00044 } 00045 }
Generated on Thu Jul 28 2022 13:44:09 by
1.7.2