Josh LeightonHailey Miles
Published

Smart Hoop

Smart Hoop is an indoor basketball hoop that counts your score, up to 5 with a distance sensor, then displays it via an led display.

IntermediateWork in progress882
Smart Hoop

Things used in this project

Story

Read more

Schematics

SMARTHOOP_Button

Button schematic to count score

SMARTHOOP_LED

Interprets score to LED's

Code

SMARTHOOP

C/C++
Code to count made hoop
// Our button wired to D0
int buttonPin = D0;
int score=0;
char myString[1];

void setup()
{

  // For input, we define the
  // pushbutton as an input-pullup
  // this uses an internal pullup resistor
  // to manage consistent reads from the device

  pinMode( buttonPin , INPUT_PULLUP); 
  


 
 Particle.variable("score", &score, INT);
}

void loop()
{
  int buttonState =( digitalRead( buttonPin ));{ 
    if( buttonState == LOW )
  {delay(2000);
     
      score=score+1;
      sprintf(myString,"%u",score);
      if(score>=6){score=0;}
       Particle.publish("score",myString);
  }

  }




  
	

}

SMARTHOOP_LED

C/C++
Lights up LEDs to reflect score
int led1 = D0; // Assign Pins to each LED
int led2 = D1;
int led3 = D2; 
int led4 = D3;
int led5 = D4;
int score;

void myHandler(const char *event, const char *data)
{
   
  score = atof(data); 
 
}
// Having declared these variables, let's move on to the setup function.
// The setup function is a standard part of any microcontroller program.
// It runs only once when the device boots up or is reset.

void setup() {
 	/
 Particle.variable("score", &score, INT);
// Identify all pins as outputs
	pinMode(led1, OUTPUT);
	pinMode(led2, OUTPUT);
	pinMode(led3, OUTPUT); 
	pinMode(led4, OUTPUT);
	pinMode(led5, OUTPUT);
	



}



void loop() {
    	
  Particle.subscribe("score", myHandler, "34003c000347353138383138" );{
      //Gets score from the cloud and runs the score scenerio
       
   if (score==0||score==6){
   digitalWrite(led1, LOW);
	digitalWrite(led2, LOW); 
	digitalWrite(led3, LOW); 
	digitalWrite(led4, LOW);
	digitalWrite(led5, LOW);
   }


	else if (score == 1){
	digitalWrite(led1, HIGH);
	digitalWrite(led2, LOW); 
	digitalWrite(led3, LOW); 
	digitalWrite(led4, LOW);
	digitalWrite(led5, LOW);
}

	else if (score ==2){
	digitalWrite(led1, HIGH);
	digitalWrite(led2, HIGH); 
	digitalWrite(led3, LOW); 
	digitalWrite(led4, LOW);
	digitalWrite(led5, LOW);
}

	else if (score ==3){
	digitalWrite(led1, HIGH);
	digitalWrite(led2, HIGH); 
	digitalWrite(led3, HIGH); 
	digitalWrite(led4, LOW);
	digitalWrite(led5, LOW);
}


	else if (score == 4){
	digitalWrite(led1, HIGH);
	digitalWrite(led2, HIGH); 
	digitalWrite(led3, HIGH); 
	digitalWrite(led4, HIGH);
	digitalWrite(led5, LOW);
}

	else if (score == 5){
	digitalWrite(led1, HIGH);
	digitalWrite(led2, HIGH); 
	digitalWrite(led3, HIGH); 
	digitalWrite(led4, HIGH);
	digitalWrite(led5, HIGH);
}
delay(2000);
}
}

Credits

Josh Leighton

Josh Leighton

1 project • 0 followers
Hailey Miles

Hailey Miles

1 project • 0 followers

Comments