Andrewbartolai
Published © GPL3+

Mini hoop score keeper

This will use a 4 digit digital display to show when a basket is made on a mini basketball hoop by making the score go up using photon 2.

BeginnerFull instructions provided6 hours54
Mini hoop score keeper

Things used in this project

Hardware components

Adafruit Short Flex Sensor [ADA1070]
×1
Photon 2
Particle Photon 2
×1
4 digit 7 segment digital display
×1

Hand tools and fabrication machines

Mini Basketball Hoop
Cardboard
Hot glue gun (generic)
Hot glue gun (generic)
Portable Battery Pack

Story

Read more

Code

Code

C/C++
This is the complete code
#include <Grove_4Digit_Display.h>
#include <cmath>


// Include Particle Device OS APIs
#include "Particle.h"


#define CLK D2//pins definitions for TM1637 and can be changed to other ports
#define DIO D3

TM1637 tm1637(CLK,DIO);

// Let Device OS manage the connection to the Particle Cloud
SYSTEM_MODE(AUTOMATIC);

// Show system, cloud connectivity, and application logs over USB
// View logs with CLI using 'particle serial monitor --follow'
SerialLogHandler logHandler(LOG_LEVEL_INFO);
int sensorPin = A0;
int sensorVal = 0;
int score = 0;
int rem = 0;
float display =0;
float display2 = 0;
float display3 =0;



// setup() runs once, when the device is first turned on
void setup() {
    Serial.println(9600);
    tm1637.init();
    tm1637.set(BRIGHT_TYPICAL);//BRIGHT_TYPICAL = 2,BRIGHT_DARKEST = 0,BRIGHTEST = 7;
    tm1637.point(POINT_OFF);
}


void loop() {
    sensorVal = analogRead(sensorPin);
    
    if(sensorVal <= 100){
        score += 1;
        delay(400);
    }
    
    if(score <= 9){
        tm1637.display(0,0);
        tm1637.display(1,0);
        tm1637.display(2,0);
        tm1637.display(3, score);
    }
    
    if(score >= 10 && score <=99){
        rem = score % 10;
        display = score / 10; 
        display = floor(display);
        tm1637.display(0,0);
        tm1637.display(1,0);
        tm1637.display(2, display);
        tm1637.display(3, rem);
        
    }
    
    if(score >= 100 && score <=999){
        rem = score % 10;
        display = score / 100;
        display2 = score % 100;
        display2 = display2 / 10;
        display2 = floor(display2);
        display = floor(display);
        tm1637.display(0,0);
        tm1637.display(1, display);
        tm1637.display(2, display2);
        tm1637.display(3, rem);
    }
    
    if(score >= 1000 && score <= 9999){
        rem = score % 10;
        display = score / 1000;
        display = floor(display);
        display2 = score % 1000;
        display2 = display2 / 100;
        display2 = floor(display2);
        display3 = score % 100;
        display3 = display3 / 10;
        display3 = floor(display3);
        tm1637.display(0, display);
        tm1637.display(1, display2);
        tm1637.display(2, display3);
        tm1637.display(3, rem);
    }

    Serial.println(score);
    delay(50);
}

Credits

Andrewbartolai
1 project • 0 followers
Contact

Comments

Please log in or sign up to comment.