Pancake Library for mbed
Embed:
(wiki syntax)
Show/hide line numbers
pancake.cpp
00001 #include "pancake.hpp" 00002 00003 Pancake::Pancake(PinName tx,PinName rx) : pc(tx,rx){ 00004 pc.baud(115200); 00005 } 00006 00007 void Pancake::sound1(uint8_t cn,sound_t &sound){ 00008 uint8_t data[4]={0x0A,cn,sound.octave,sound.toneColor<<4|sound.scale}; 00009 sendCommand(data,4); 00010 } 00011 00012 void Pancake::sound(sound_t sounds[4]){ 00013 uint8_t data[9]={0x09,0,0,0,0,0,0,0,0}; 00014 data[1] = sounds[0].octave; 00015 data[2] = sounds[0].toneColor<<4|sounds[0].scale; 00016 data[3] = sounds[1].octave; 00017 data[4] = sounds[1].toneColor<<4|sounds[1].scale; 00018 data[5] = sounds[2].octave; 00019 data[6] = sounds[2].toneColor<<4|sounds[2].scale; 00020 data[7] = sounds[3].octave; 00021 data[8] = sounds[3].toneColor<<4|sounds[3].scale; 00022 00023 sendCommand(data,9); 00024 } 00025 00026 void Pancake::setMusic(uint8_t channel,bool mode,uint8_t tempo, 00027 uint8_t toneColor,uint8_t score[],uint8_t scoreSize){ 00028 uint8_t data[3+scoreSize]; 00029 data[0] = 0x0b;//command code 00030 data[1] = channel; 00031 data[2] = mode; 00032 data[3] = (tempo<<4)|toneColor; 00033 for(uint8_t i= 4;i < scoreSize + 4;i++){ 00034 data[i] = score[i - 4]; 00035 } 00036 00037 sendCommand(data,scoreSize + 4); 00038 } 00039 00040 void Pancake::playMusic(){ 00041 uint8_t data[2]={0x0c,0x01}; 00042 sendCommand(data,2); 00043 } 00044 00045 void Pancake::stopMusic(){ 00046 uint8_t data[2]={0x0c,0x00}; 00047 sendCommand(data,2); 00048 } 00049 00050 void Pancake::clearScreen(P_Color color){ 00051 uint8_t data[2] = {0x00,uint8_t(color)}; 00052 sendCommand(data,2); 00053 } 00054 00055 void Pancake::writeLine(uint8_t sx,uint8_t sy,uint8_t ex,uint8_t ey, 00056 P_Color color){ 00057 uint8_t data[6] = {0x01,sx,sy,ex,ey,uint8_t(color)}; 00058 sendCommand(data,6); 00059 } 00060 00061 void Pancake::writeCircle(uint8_t centerx,uint8_t centery,uint8_t radius,P_Color color){ 00062 uint8_t data[5] = {0x0e,centerx,centery,radius,uint8_t(color)}; 00063 sendCommand(data,5); 00064 } 00065 00066 00067 00068 00069 void Pancake::sendCommand(uint8_t data[],uint8_t length) 00070 { 00071 uint8_t i = 0; 00072 pc.putc(0x80); 00073 pc.putc(length + 2); 00074 00075 while(i < length ){ 00076 pc.putc(data[i]); 00077 i++; 00078 } 00079 }
Generated on Fri Jul 15 2022 18:42:55 by 1.7.2