Skip to content

Commit

Permalink
remove clear()
Browse files Browse the repository at this point in the history
  • Loading branch information
botamochi6277 committed Aug 26, 2017
1 parent 857e1db commit a096d06
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 9 deletions.
2 changes: 1 addition & 1 deletion i2cLCDanalog/i2cLCDanalog.ino
Expand Up @@ -44,7 +44,7 @@ void loop() {
average = total / numReadings;

if(cnt%10){
mylcd.clear();
mylcd.move(0,0);
sprintf(s, "A0 avr = %04d", average);
for(int i=0;i<16;i++){
mylcd.writeData(s[i]);
Expand Down
13 changes: 13 additions & 0 deletions i2cLCDgame/i2cLCD.h
Expand Up @@ -90,6 +90,19 @@ class i2cLCD {
}
delay(20);
}
/**
* @brief fill the display with one charactor
* @param c filling charactor
*/
void fill(char c){
for(int j = 0; j < 2; ++j){
move(j,0);
for(int i=0;i<16;++i){
writeData(c);
}
}

}
};

#endif
40 changes: 32 additions & 8 deletions i2cLCDgame/i2cLCDgame.ino
Expand Up @@ -7,6 +7,7 @@ int const BUTTON_PIN = 2;

int playerPos[2];// player position, x-y
int obstaclePos[10][2];// obstacle position, first index: obstacleId,second index: positon
char pixels[16][2];

int numObs = 0;
unsigned long cnt = 0;
Expand Down Expand Up @@ -72,18 +73,33 @@ void loop() {
}

//display
mylcd.clear();

// fill pixels with ` `(space)
for(int x = 0;x<16;++x){
for(int y = 0; y<2 ;++y){
pixels[x][y] = ' ';
}
}

for(int i=0;i < numObs;++i){
if(obstaclePos[i][0] > -1){
mylcd.move(obstaclePos[i][1],obstaclePos[i][0]);
mylcd.writeData('*');
pixels[obstaclePos[i][0]][obstaclePos[i][1]] = '*';
}
}
mylcd.move(playerPos[1],playerPos[0]);

if(!isCrush){
mylcd.writeData('>');
pixels[playerPos[0]][playerPos[1]] = '>';
}else{
mylcd.writeData('X');
pixels[playerPos[0]][playerPos[1]] = 'X';
}

// write display

for(int y = 0; y<2 ;++y){
mylcd.move(y,0);
for(int x = 0;x<16;++x){
mylcd.writeData(pixels[x][y]);
}
}

cnt++;
Expand All @@ -98,7 +114,7 @@ void loop() {

// Game over
delay(3000);
mylcd.clear();
mylcd.fill(' ');
mylcd.move(0,0);
char msg[] = "** GAME OVER **";
for(int i=0;i<16;i++){
Expand All @@ -114,5 +130,13 @@ void loop() {
isCrush = false;
cnt = 0;
numObs = 0;
delay(10000);

for(int i=0;i < numObs;++i){
obstaclePos[i][0] = 0;
obstaclePos[i][1] = 0;
}
while(digitalRead(BUTTON_PIN)){
delay(30);
}

}

0 comments on commit a096d06

Please sign in to comment.