login signup | whydoineedaccount?
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include <LiquidCrystal.h>
#include <Streaming.h>


LiquidCrystal lcd( 18, 11, 19, 20, 21, 22, 23 );

int status = 15;
int position = 0;
int mod = 0;
unsigned long prev = 0;
int score = 0;
int astx = 16;
int asty = 0;
void setup( )
{
  pinMode( status, OUTPUT ); 
  digitalWrite( status, HIGH );
  Serial.begin( 9600 );
  randomSeed( 4 ); //fair dice roll
  asty = random( 2 );
}

void loop( ) {  
  int x;
  
  x = digitalRead( 8 );
  if( x == 0 ) mod = 1;
  if ( millis( ) - prev > 200 ) {
    randomSeed( millis( ) );
    astx--;
    if( astx<=0 ) {
       if( asty==position ) {
         gameover( ); 
       } else {
         score++;
         astx = 16;
         asty = random( 2 );
       }
       
       
    }
    
    if( astx>3 && random( 2 ) == 1) asty = random( 2 );
    
    if( mod == 1 ) {
      mod = 0;
      position = position==1?0:1; 
    }
    lcd.clear( );
    
    prev = millis( );  
    position += mod;
    
    lcd.setCursor( astx, asty );
    lcd.print( "*" );
    lcd.setCursor( 0, position );
    lcd.print( "> " );
  }
  delay( 100 );
}

void gameover( ) {
  lcd.setCursor( 0, 0 );
  lcd.print( "GAME OVER!" );
  lcd.setCursor( 0, 1 );
  lcd.print( "Score: " );
  lcd.print( score );
  
  score = 0;
  astx = 16;
  asty = random( 2 );
  delay( 5000 );
}
back to top ↑

Did you know, that…?

wklej.org it's a NoPaste site, which allows you to paste here any text, or source code, which will be available under special URL. Thanks to this, you can make forums or IRC channels more readable