So here is my project:
I saw this pop-a-shot-esque basketball hoop on Instructables and liked the concept, but wanted to build one with a cleaner design. I picked up a door-hanging hoop with a clear backboard and am mounting this 14-segment alphanumeric display behind the board at the top center, connected to an Arduino Micro, pulling data from this distance sensor.
Hardware wise, I have the following setup:
Arduino Micro
5v > 5v rail
GND > GND rail
A0 > distance sensor (out)
2/SDA > alpha SDA
3/SCL > alpha SCL
Display Sensor
OUT > adruino micro A0
VIN > 5v rail
GND > GND rail
14-Segment Alphanumeric Display
Vi26 > 5v rail
VCC > 5v rail
GND >GND rail
SDA > adrunio micro 2/SDA
SCL > adruino micro 3/SCL
Code-wise, I figure "create an integer, every time the display trigger trips add 1, always display that integer on the alpha display." Easy peasy.
Ok, don't judge, and all the commenting was so I could keep track of what I believed was going on...
Code: Select all
//include libraries
#include <Wire.h>
#include "Adafruit_LEDBackpack.h"
#include "Adafruit_GFX.h"
//create Adafruit Alphanumeric Display object
Adafruit_AlphaNum4 alpha4 = Adafruit_AlphaNum4();
//define integers
int sensorPin = A0;
int sensorValue = 0;
int score = 1;
void setup() {
//set sensor pin to INPUT
pinMode(sensorPin, INPUT);
//set BAUD rate
Serial.begin(9600);
//start display
alpha4.begin(0x70);
//write zeros to all positions
alpha4.writeDigitAscii(0, '0');
alpha4.writeDigitAscii(1, '0');
alpha4.writeDigitAscii(2, '0');
alpha4.writeDigitAscii(3, '0');
//display newly written values
alpha4.writeDisplay();
}
//define spaces for display buffer?
char displaybuffer[4] = {' ', ' ', ' ', ' '};
void loop() {
//declare character array
char b[5];
//declare string
String str;
//convert score integer to string
str=String(score);
//pass value of string to array
str.toCharArray(b,5);
//check sensor to see if voltage is LOW
sensorValue = analogRead(sensorPin);
if (sensorValue < 200) {
score++;
Serial.write(b);
delay(1500);
}
}
So I don't understand a few things.
1 - What's the deal with converting integers > strings > character arrays? I mean, why can't the integers just be happy with who they are, am I right? Who are these displays to demand otherwise? (in my best Jerry Seinfeld impersonation)
2 - What is the base information around writing data to displays like this, opposed to the simplified version used with this backpack (I saw a bunch of similar commands used for other projects/displays so I figure this is part of C++?)
3 - (this one probably comes with knowledge of #2) What is the base information around writing data to this specific backpack more-so than what is listed on the tutorial page?
4 - If I just want this to work, what's the code to tell the display "alphadisplay.blah blah(scoreinteger)"
Seriously, I would love actual direction into understanding the elements I am trying to access here, but per #4 would just take the answer. If anyone wants to recommend online resources I am all about reading.