Notes.nxc
From RoboWiki
/* program notes, draws noteso on the LCD display Programmed by Ivan Ryger */ #define C 523 //Hz #define D 587 #define E 659 #define F 698 #define G 784 #define A 880 #define H 988 #define C2 1047 int freq[8]={C,D,E,F,G,A,H,C2};//array storing melody int i; void Note(int freq, int xPos)//draws note on LCD { const int R=5;//diameter of the note base const int yShift=10;//Y shift const int d=2*R;//differentia of arithmetical progression switch(freq) { case C: CircleOut(xPos,yShift,R);break;//R-diameter, k-const Ypos case D: CircleOut(xPos,yShift+d,R);break; case E: CircleOut(xPos,yShift+2*d,R);break; case F: CircleOut(xPos,yShift+3*d,R);break; case G: CircleOut(xPos,yShift+4*d,R);break; case A: CircleOut(xPos,yShift+5*d,R);break; case H: CircleOut(xPos,yShift+6*d,R);break; case C2:CircleOut(xPos,yShift+7*d,R);break; } } task Battery() //controls battery state { const int BAT_LOW=3800; if(BatteryLevel()<BAT_LOW) PlayTone(1000,500); Wait(500); PlayTone(2000,500); Wait(500); PlayTone(1000,500); Wait(500); PlayTone(2000,500); Wait(500); TextOut(10,LCD_LINE3,"sorry, Battery is low, I go sleeping, bye"); Wait(5000);// wait a while so user can read the text ForceOff(true);//force the NXT to off state } task main() { start Battery; SetVolume(2);//value can be in interval 0-4 for(i=0;i<ArrayLen(freq);i++) { PlayTone(freq[i],100); Note(freq[i],10*i); Wait(100); } }