Kian Calnan
Published

Bouncing Ball

This quick and easy project uses an LED matrix to make a light bounce around forever as entertaining and entrancing distraction from life.

BeginnerFull instructions provided5,576
Bouncing Ball

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
Adafruit 0.8" 8x16 LED Matrix FeatherWing Display - Red
×1
Jumper wires (generic)
Jumper wires (generic)
×4

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

Schematic of Device

Code

Bouncing_Ball

Arduino
#include <Wire.h>
#include <Adafruit_GFX.h> // Adafruit GFX Library
#include "Adafruit_LEDBackpack.h" //Adafruit LED Backpack Library

Adafruit_8x16matrix matrix = Adafruit_8x16matrix();

void setup() {
  Serial.begin(9600);
  Serial.println("16x8 LED Matrix Test");
  
  matrix.begin(0x70);  // pass in the address
  
}

static const uint8_t PROGMEM // the key to the LED Matrix
  smile_bmp[] =
  { B00111100,
    B01000010,
    B10100101,
    B10000001,
    B10100101,
    B10011001,
    B01000010,
    B00111100 },
  neutral_bmp[] =
  { B00111100,
    B01000010,
    B10100101,
    B10000001,
    B10111101,
    B10000001,
    B01000010,
    B00111100 },
  frown_bmp[] =
  { B00111100,
    B01000010,
    B10100101,
    B10000001,
    B10011001,
    B10100101,
    B01000010,
    B00111100 };

void loop() {

  int x = 0;
  int y = 0;
  int a = 0;
  int tell = 1; // determines if the x value is hitting something
  int till = 1; // determines if the y value is hitting something
  while (a == 0){ // always true
    matrix.drawPixel(x, y, LED_ON);  
    matrix.writeDisplay();  // write the changes we just made to the display
    delay(40); // time ball spends on
    matrix.drawPixel(x, y, LED_OFF);  
    matrix.writeDisplay();  // write the changes we just made to the display
    delay(40); // time ball spend off
    
    if (x == 7){ // all these if statements determine where the ball is on the LED matrix
      tell = 0;  // and adjust it as is needed
    }
  
    
    if (x == 0){
      tell = 1;
    }
    
    if (y == 15){
      till = 0;
    }
  
    
    if (y == 0){
      till = 1;
    }
  
    
    if(tell == 1){
      x++;
    }else{
      x--;
    }
   if(till == 1){
    y++;
   }else{
    y--;
   }
 }
}

Credits

Kian Calnan
1 project • 1 follower
Contact

Comments

Please log in or sign up to comment.