Hey guys and girls,
I'm pretty stuck...
For my skillset and knowledge this is the best i can do but can't figure out how to keep a reset button always 'hot' so whenever in the game i push it, the game will reset of restart.
Might be a simple one for you but i can't figure it out.
It's a kind of Beerpong...
LDR sensor to look for a ball in the cup (shadow from light when ball goes through cup).
And as you might notice some sweet RGB matrix animations together with neopixel strips.
It is single player but tend to make it multiplayer over Wire code, Wifi or Bluetooth after Christmas.
But for the school Christmas party i'd like to get it working.
This is what i got so far:
//RGBmatrix
#include <avr/pgmspace.h>
#include <Adafruit_GFX.h>
#include <RGBmatrixPanel.h>
#define CLK 8
#define LAT A3
#define OE 9
#define A A0
#define B A1
#define C A2
RGBmatrixPanel matrix(A, B, C, CLK, LAT, OE, false);
#define LOGO16_GLCD_HEIGHT 16
#define LOGO16_GLCD_WIDTH 32
#define F2(progmem_ptr) (const __FlashStringHelper *)progmem_ptr
//Neopixel
#include <Adafruit_NeoPixel.h>
#include <avr/power.h>
#define PIN 10
#define NUMPIXELS 1
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
//BITMAP characters
const unsigned char PROGMEM bitmap1[] =
{
0xaa, 0xaa, 0xaa, 0xaa, 0x55, 0x55, 0x55, 0x55, 0xaa, 0xaa, 0xaa, 0xaa, 0x55, 0x55, 0x55,
0x55, 0xaa, 0xaa, 0xaa, 0xaa, 0x55, 0x55, 0x55, 0x55, 0xaa, 0xaa, 0xaa, 0xaa, 0x55, 0x55,
0x55, 0x55, 0xaa, 0xaa, 0xaa, 0xaa, 0x55, 0x55, 0x55, 0x55, 0xaa, 0xaa, 0xaa, 0xaa, 0x55,
0x55, 0x55, 0x55, 0xaa, 0xaa, 0xaa, 0xaa, 0x55, 0x55, 0x55, 0x55, 0xaa, 0xaa, 0xaa, 0xaa,
0x55, 0x55, 0x55, 0x55,
};
const unsigned char PROGMEM bitmap2[] =
{
0x55, 0x55, 0x55, 0x55, 0xaa, 0xaa, 0xaa, 0xaa, 0x55, 0x55, 0x55, 0x55, 0xaa, 0xaa, 0xaa,
0xaa, 0x55, 0x55, 0x55, 0x55, 0xaa, 0xaa, 0xaa, 0xaa, 0x55, 0x55, 0x55, 0x55, 0xaa, 0xaa,
0xaa, 0xaa, 0x55, 0x55, 0x55, 0x55, 0xaa, 0xaa, 0xaa, 0xaa, 0x55, 0x55, 0x55, 0x55, 0xaa,
0xaa, 0xaa, 0xaa, 0x55, 0x55, 0x55, 0x55, 0xaa, 0xaa, 0xaa, 0xaa, 0x55, 0x55, 0x55, 0x55,
0xaa, 0xaa, 0xaa, 0xaa,
};
//Miscellaneous
int resetPin = 11;
int var;
int varloop;
int clockVar;
int bierLvl;
int points = 0;
int sensorThreshold = 350;
int pointsThreshold = 3;
//////////////////////////////////////////////////////////////////////////////////////////// SETUP
void setup() {
Serial.begin(9600);
pinMode(11, INPUT_PULLUP);
matrix.begin();
matrix.setTextWrap(false); // Allow text to run off right edge
matrix.setTextSize(2);
pixels.begin();
fillGlass();
}
//////////////////////////////////////////////////////////////////////////////////////////// LOOP
void loop(){
if (digitalRead(resetPin) == HIGH)
{
pushStart();
}
pixels.setPixelColor(0, pixels.Color(255,255,255));
pixels.show();
Serial.println(analogRead(5));
matrix.drawRect(0, 0, 32, 16, matrix.Color333(0, 0, 7));
matrix.setCursor(11,1);
matrix.setTextSize(2);
matrix.setTextColor(matrix.Color333(7,7,7));
matrix.print(points);
if (analogRead(5) > sensorThreshold){
score();
points++;
}
if (points == pointsThreshold){
winner();
}
}
//////////////////////////////////////////////////////////////////////////////////////////// VOIDS
//here where some voids but i exceeded the maximum characters for this forum..
As you might notice, i already tried to keep my void loop() as small as possible.
here the void loop() where i'd like to have some sort of code so that the restart button is always active
void loop(){
if (digitalRead(resetPin) == HIGH)
{
pushStart();
}
pixels.setPixelColor(0, pixels.Color(255,255,255));
pixels.show();
Serial.println(analogRead(5));
matrix.drawRect(0, 0, 32, 16, matrix.Color333(0, 0, 7));
matrix.setCursor(11,1);
matrix.setTextSize(2);
matrix.setTextColor(matrix.Color333(7,7,7));
matrix.print(points);
if (analogRead(5) > sensorThreshold){
score();
points++;
}
if (points == pointsThreshold){
winner();
}
}
As this code is the 2.0 of the same game i had this problem before and a friend suggested this piece of code, but i don't get it. does this make any sense to you guys?
//boolean for 'push start' animation
bool checkPin(int pin, bool state, int duration){
unsigned long end = millis() + duration;
while(millis()<duration){
if(digitalRead(pin)==state) return true;
}
return false;
}
Would be glad if you guys could help me out.
Cheers!
P.