Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Arduino.h>
- #include <Wire.h>
- #include <LiquidCrystal.h>
- #include <LedControl.h>
- LedControl lc = LedControl(7, 9, 8);
- const int rs = 12, en = 11, d4 = 2, d5 = 3, d6 = 4, d7 = 5;
- LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
- int data[10][10] = {
- {4,7,2,1,2,2,4,6,6,3},
- {6,8,7,5,4,1,5,2,7,6},
- {2,7,4,2,4,4,8,4,2,8},
- {4,8,7,8,2,3,1,5,5,6},
- {5,6,8,4,6,4,3,7,4,3},
- {3,5,5,3,6,8,1,8,6,6},
- {4,7,8,8,1,8,3,6,2,5},
- {4,2,5,5,8,5,6,5,3,2},
- {1,4,1,5,8,1,8,7,7,5},
- {2,3,2,6,8,8,6,1,2,5}
- };
- int flashes = 0;
- void flash(int x,int y){
- flashes++;
- for (int yy = y-1; yy <= y+1; yy++) {
- for (int xx = x-1; xx <= x+1; xx++) {
- if((x==xx && y == yy) || xx<0||yy<0||xx>9||yy>9)continue;
- data[yy][xx]++;
- if(data[yy][xx]==10){
- flash(xx,yy);
- data[yy][xx]++;
- }
- }
- }
- }
- bool step(){
- for (int y = 0; y < 10; y++) {
- for (int x = 0; x < 10; x++) {
- data[y][x]++;
- if(data[y][x]==10){
- flash(x,y);
- data[y][x]++;
- }
- }
- }
- int amount = 0;
- for (int y = 0; y < 10; y++) {
- for (int x = 0; x < 10; x++) {
- if(data[y][x] > 9)
- {
- lc.setLed(0,x,y,true);
- amount ++;
- data[y][x] = 0;
- }
- else{
- lc.setLed(0,x,y,false);
- }
- }
- }
- if(amount == 100){
- return true;
- }
- return false;
- }
- int steps = 1;
- void setup() {
- Serial.begin(9600);
- while (!Serial);
- lc.shutdown(0,false);
- lc.setIntensity(0,8);
- lc.clearDisplay(0);
- lcd.begin(16, 2);
- lcd.setCursor(0, 0);
- lcd.print(" FLASHES! ");
- lcd.setCursor(0, 1);
- lcd.print( 0 ); delay(1000);
- while(!step()){
- steps++;
- lcd.setCursor(0, 1);
- lcd.print( steps);
- delay(25);
- }
- delay(1000);
- lc.clearDisplay(0);
- }
- void loop() {
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement