![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Usb Device Interface, protocol, and programming homework #4 Audio Control device
Dependencies: C12832_lcd USBDevice mbed
Diff: bargraph.cpp
- Revision:
- 0:69eb9d19fb91
- Child:
- 1:948ffad3284f
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bargraph.cpp Tue Jul 30 22:35:10 2013 +0000 @@ -0,0 +1,55 @@ + #include "bargraph.h" + bargraph::bargraph(C12832_LCD *inlcd,int maxlevelsIn,int Xin,int Yin,int widthIn,int heightIn){ + lcd=inlcd; + level=0; + lastLevel=0; + if(maxlevelsIn<=32 && maxlevelsIn >=4) + maxlevels=maxlevelsIn; + else + maxlevels=32; + if(Xin>=0 && Xin<=127-maxlevels) + x=Xin; + else + x=0; + if(Yin>=0 && Yin<=31-maxlevels) + y=Yin; + else + y=0; + if(widthIn>maxlevels && widthIn<128) + width=widthIn-1; + else + width=127; + if(heightIn>=(maxlevels-1) && heightIn<31) + height=heightIn; + else + height=31; + leveladjust=(height+1)/maxlevels; + levelwidth=(width+1)/maxlevels; + } + + void bargraph::setMaxLevel(int maxlevels){ + lcd->fillrect(x, y, x+width,y+height, 0); + leveladjust=(height+1)/maxlevels; + levelwidth=(width+1)/maxlevels; + } + + void bargraph::setLevel(int level){ + this->level=level; + } + + void bargraph::updateBargraph(){ + if(lcd!=NULL) { + if(level!=lastLevel) { + for(int i = 0 ; i<lastLevel;i++) { + lcd->fillrect(x+levelwidth*(i), y, x+levelwidth*(i+1)-1, y+i*leveladjust, 0); + } + for(int i = 0 ; i<level;i++) { + lcd->fillrect(x+levelwidth*(i), y, x+levelwidth*(i+1)-1, y+i*leveladjust, 1); + } + lastLevel=level; + } + } + }; + + +