Skip to content

Commit

Permalink
remove button library with manual coding
Browse files Browse the repository at this point in the history
  • Loading branch information
gavinlyonsrepo committed Jun 27, 2018
1 parent 78aef2e commit f3c19d4
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 21 deletions.
10 changes: 4 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,17 @@ Overview
--------------------------------------------
* Name: timer_arduino
* Title : Countdown Timer, arduino based.
* Description: Countdown Timer: 1-99 minutes. Output(mm:ss) to seven segment display(TM1637) and Buzzer.
Push button to start. 10K Pot used for time select input.
* Description: Countdown Timer: Range 1-99 minutes.
Output time (mm:ss) to seven segment display(TM1637) and Audio to Buzzer.
Input: Push button to start. 10K Pot used for time select.
* Author: Gavin Lyons

libraries
--------------------------
* https://github.com/avishorp/TM1637
* Version 1.1.0
* TM1637Display.h // Tm1637 module
* TM1637Display.h // to drive the Tm1637 module

* https://github.com/JChristensen/JC_Button
* Version 2.0-1
* JC_Button.h // push button lib

Software Used
------------------
Expand Down
44 changes: 29 additions & 15 deletions timer_arduino.ino
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@
// Version 1.1.0
#include <TM1637Display.h> // Tm1637 module

// https://github.com/JChristensen/JC_Button
// Version 2.0-1
#include <JC_Button.h> // push button lib

//*************************** GLOBALS ********************

Expand All @@ -29,8 +26,13 @@ TM1637Display display(CLK, DIO);
int buzzer = 9;//the pin of the active buzzer

// Button
#define btn_start_pin 2
Button btn_start(btn_start_pin);
#define buttonPin 2
int buttonState; // the current reading from the input pin
int lastButtonState = HIGH; // the previous reading from the input pin
// the following variables are unsigned longs because the time, measured in
// milliseconds, will quickly become a bigger number than can be stored in an int.
unsigned long lastDebounceTime = 0; // the last time the output pin was toggled
unsigned long debounceDelay = 50; // the debounce time; increase if the output flickers
int count_start = 0;


Expand Down Expand Up @@ -60,8 +62,7 @@ void setup() {

// button setup
// Setup pins for button enable internal pull-up resistors
digitalWrite(btn_start_pin, HIGH);
btn_start.begin();
digitalWrite(buttonPin, HIGH);

//display setup
display.setBrightness(0x0c);
Expand All @@ -78,18 +79,33 @@ void setup() {

//******************* MAIN LOOP *****************
void loop() {
// read the pot
if (count_start == 0)
{
potRead();
}

// start button press
if (btn_start.read()) {
if (btn_start.wasPressed())
{
TestButton();
// read and debounce push button.
int reading = digitalRead(buttonPin);
// If the switch changed?
if (reading != lastButtonState) {
// reset the debouncing timer
lastDebounceTime = millis();
}

if ((millis() - lastDebounceTime) > debounceDelay) {
// if the button state has changed:
if (reading != buttonState) {
buttonState = reading;
// start timer if the new button state is low
if (buttonState == LOW) {
TestButton();
}
}
}

// save the reading.
lastButtonState = reading;
delay(5);
}

Expand All @@ -112,7 +128,7 @@ void TestButton()
// includes smoothing the analog sample by taking avergae of 10 readings
void potRead()
{
unsigned long average = 0;
unsigned long average = 0;
// subtract the last reading:
total = total - readings[readIndex];
readings[readIndex] = map(analogRead(potPin), 0, 1023, 1, 99);
Expand All @@ -125,7 +141,6 @@ void potRead()
}
average = total / numReadings;
Serial.println(average);
Serial.println(total);
timeLimit = ((average * 60) * 1000);
average = average * 100 ;
display.showNumberDecEx(average, 0x40, true);
Expand All @@ -148,7 +163,6 @@ void my_buzzer (void)
// run for 250*1400ms = 3.5 minutes
for (j = 0; j < 250; j++)
{
Serial.println(j);
//output an frequency
for (i = 0; i < 100; i++)
{
Expand Down

0 comments on commit f3c19d4

Please sign in to comment.