Hi,
I am new to arduino and I need some help for my projet. It is for a sport (dodgeball). It a box with lights, buttons and 2x 7 segements display (see images) I want that when you press the blue button, the blue lights light up and a 10 sec countdown start on the 2x7 segements display (same thing with the red buttons and lights). I need that the buttons to be hold press for the countdown to start and the countdown to reset when you released the bouton (using arcade buttons). There will be a clock timer too using a lcd panel.
I am using a arduino uno for now, but in the futur I am will use a mega 2560 (broke the usb, waiting for parts )
Using TPIC6C596 for the 7 segements:
There code I write for the boutons:
int ledPinRED = 11;
int ledPinBLUE = 10;
int butttonREDpin = 8;
int butttonBLUEpin = 9;
byte leds = 0;
void setup()
{
pinMode(ledPinRED, OUTPUT);
pinMode(ledPinBLUE, OUTPUT);
pinMode(butttonREDpin, INPUT_PULLUP);
pinMode(butttonBLUEpin, INPUT_PULLUP);
}
void loop()
{
if (digitalRead(butttonREDpin) == LOW)
{
digitalWrite(ledPinRED, HIGH);
}
if (digitalRead(butttonREDpin) == HIGH)
{
digitalWrite(ledPinRED, LOW);
}
if (digitalRead(butttonBLUEpin) == LOW)
{
digitalWrite(ledPinBLUE, HIGH);
}
if (digitalRead(butttonBLUEpin) == HIGH)
{
digitalWrite(ledPinBLUE, LOW);
}
}
This is the code for testing the TPIC6C596, found there:
https://learn.sparkfun.com/tutorials/large-digit-driver-hookup-guide#board-overview
/*
Controlling large 7-segment displays
By: Nathan Seidle
SparkFun Electronics
Date: February 25th, 2015
License: This code is public domain but you buy me a beer if you use this and we meet someday (Beerware license).
This code demonstrates how to post two numbers to a 2-digit display usings two large digit driver boards.
Here's how to hook up the Arduino pins to the Large Digit Driver IN
Arduino pin 6 -> CLK (Green on the 6-pin cable)
5 -> LAT (Blue)
7 -> SER on the IN side (Yellow)
5V -> 5V (Orange)
Power Arduino with 12V and connect to Vin -> 12V (Red)
GND -> GND (Black)
There are two connectors on the Large Digit Driver. 'IN' is the input side that should be connected to
your microcontroller (the Arduino). 'OUT' is the output side that should be connected to the 'IN' of addtional
digits.
Each display will use about 150mA with all segments and decimal point on.
*/
//GPIO declarations
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
byte segmentClock = 6;
byte segmentLatch = 5;
byte segmentData = 7;
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
void setup()
{
Serial.begin(9600);
Serial.println("Large Digit Driver Example");
pinMode(segmentClock, OUTPUT);
pinMode(segmentData, OUTPUT);
pinMode(segmentLatch, OUTPUT);
digitalWrite(segmentClock, LOW);
digitalWrite(segmentData, LOW);
digitalWrite(segmentLatch, LOW);
}
int number = 0;
void loop()
{
showNumber(number); //Test pattern
number++;
number %= 100; //Reset x after 99
Serial.println(number); //For debugging
delay(500);
}
//Takes a number and displays 2 numbers. Displays absolute value (no negatives)
void showNumber(float value)
{
int number = abs(value); //Remove negative signs and any decimals
//Serial.print("number: ");
//Serial.println(number);
for (byte x = 0 ; x < 2 ; x++)
{
int remainder = number % 10;
postNumber(remainder, false);
number /= 10;
}
//Latch the current segment data
digitalWrite(segmentLatch, LOW);
digitalWrite(segmentLatch, HIGH); //Register moves storage register on the rising edge of RCK
}
//Given a number, or '-', shifts it out to the display
void postNumber(byte number, boolean decimal)
{
// - A
// / / F/B
// - G
// / / E/C
// -. D/DP
#define a 1<<0
#define b 1<<6
#define c 1<<5
#define d 1<<4
#define e 1<<3
#define f 1<<1
#define g 1<<2
#define dp 1<<7
byte segments;
switch (number)
{
case 1: segments = b | c; break;
case 2: segments = a | b | d | e | g; break;
case 3: segments = a | b | c | d | g; break;
case 4: segments = f | g | b | c; break;
case 5: segments = a | f | g | c | d; break;
case 6: segments = a | f | g | e | c | d; break;
case 7: segments = a | b | c; break;
case 8: segments = a | b | c | d | e | f | g; break;
case 9: segments = a | b | c | d | f | g; break;
case 0: segments = a | b | c | d | e | f; break;
case ' ': segments = 0; break;
case 'c': segments = g | e | d; break;
case '-': segments = g; break;
}
if (decimal) segments |= dp;
//Clock these bits out to the drivers
for (byte x = 0 ; x < 8 ; x++)
{
digitalWrite(segmentClock, LOW);
digitalWrite(segmentData, segments & 1 << (7 - x));
digitalWrite(segmentClock, HIGH); //Data transfers to the register on the rising edge of SRCK
}
}
And the code a found for the clock timer:
#include "Wire.h"
#include "LiquidCrystal_I2C.h"
LiquidCrystal_I2C LCD(0x27, 16, 2);
boolean button1WasUp = true;
boolean button2WasUp = true;
boolean button3WasUp = true;
boolean button4WasUp = true;
byte w = 0;
int SEC = 0;
int MIN = 0;
unsigned long timer;
void setup() {
pinMode(2, INPUT_PULLUP);
pinMode(4, INPUT_PULLUP);
pinMode(6, INPUT_PULLUP);
pinMode(8, INPUT_PULLUP);
pinMode(10, OUTPUT);
pinMode(12, OUTPUT);
digitalWrite(10, HIGH);
LCD.init();
LCD.backlight();
LCD.setCursor(2, 0);
LCD.print("TIMER STOP");
LCD.setCursor(5, 1);
LCD.print(MIN);
LCD.print(" : ");
LCD.print(SEC);
}
void loop() {
boolean button1IsUp = digitalRead(2);
boolean button2IsUp = digitalRead(4);
boolean button3IsUp = digitalRead(6);
boolean button4IsUp = digitalRead(8);
if (button1WasUp && !button1IsUp) {
delay(10);
button1IsUp = digitalRead(2);
if (!button1IsUp) {
MIN = MIN - 1; SEC = 0;
if (MIN < 0) { MIN = 0; }
LCD.clear();
LCD.setCursor(2, 0);
LCD.print("TIMER STOP");
LCD.setCursor(5, 1);
LCD.print(MIN);
LCD.print(" : ");
LCD.print(SEC);
}
}
button1WasUp = button1IsUp;
if (button2WasUp && !button2IsUp) {
delay(10);
button2IsUp = digitalRead(4);
if (!button2IsUp) {
MIN = MIN + 1; SEC = 0;
LCD.clear();
LCD.setCursor(2, 0);
LCD.print("TIMER STOP");
LCD.setCursor(5, 1);
LCD.print(MIN);
LCD.print(" : ");
LCD.print(SEC);
}
}
button2WasUp = button2IsUp;
if (button3WasUp && !button3IsUp && MIN > 0) {
delay(10);
button3IsUp = digitalRead(6);
if (!button3IsUp) {
if (SEC == 0) { SEC = 60; MIN = MIN - 1; }
if (MIN < 0 ) { MIN = 0; }
digitalWrite(10, LOW);
w = 1;
}
}
button3WasUp = button3IsUp;
if (button4WasUp && !button4IsUp) {
delay(10);
button4IsUp = digitalRead(8);
if (!button4IsUp) {
MIN = 0; SEC = 0;
digitalWrite(10, HIGH);
LCD.clear();
LCD.setCursor(2, 0);
LCD.print("TIMER STOP");
LCD.setCursor(5, 1);
LCD.print(MIN);
LCD.print(" : ");
LCD.print(SEC);
}
}
button4WasUp = button4IsUp;
while (w == 1 ) {
if (millis() - timer > 995) {
timer = millis();
SEC = SEC - 1;
if (SEC == 0 && MIN == 0) {
LCD.clear();
LCD.setCursor(2, 0);
LCD.print("TIMER STOP");
LCD.setCursor(5, 1);
LCD.print(MIN);
LCD.print(" : ");
LCD.print(SEC);
digitalWrite(10, HIGH);
tone(12, 100);
delay(3000);
noTone(12);
w = 0;
}
if (SEC == 0) {
SEC = 59; MIN = MIN - 1;
if (MIN < 0 ) { MIN = 0; }
}
if (w == 1) {
LCD.clear();
LCD.setCursor(2, 0);
LCD.print("TIMER START");
LCD.setCursor(5, 1);
LCD.print(MIN);
LCD.print(" : ");
LCD.print(SEC);
}
}
boolean button3IsUp = digitalRead(6);
if (button3WasUp && !button3IsUp) {
delay(10);
button3IsUp = digitalRead(6);
if (!button3IsUp) {
LCD.setCursor(2, 0);
LCD.print("TIMER STOP");
w = 0;
}
}
button3WasUp = button3IsUp;
}
}
Thank you for your help
(sorry for the bad english, not a native speaker)