学会UserButton之后很想联合学过的这三个interface写点东西,好吧,小程序一个。。
定时器控制3个led的亮灭,UserButton用来控制定时器的开关。
#include<Timer.h> #include<UserButton.h> module ButtonTest2C @safe() { uses { interface Boot; interface Leds; interface Get<button_state_t>; interface Notify<button_state_t>; interface Timer<TMilli> as Timer0; } } implementation { uint8_t led_state=1; bool isrunning=FALSE; event void Boot.booted() { call Notify.enable(); call Timer0.startPeriodic(2000); } event void Timer0.fired() { call Leds.set((led_state++)%8); } event void Notify.notify(button_state_t state) { isrunning=call Timer0.isRunning(); if(state==BUTTON_PRESSED) { if(isrunning==TRUE) call Timer0.stop(); else call Timer0.startPeriodic(2000); } } }