You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
63 lines
2.2 KiB
63 lines
2.2 KiB
3 years ago
|
/* SevSeg Counter Example
|
||
|
|
||
|
Copyright 2017 Dean Reading
|
||
|
|
||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||
|
you may not use this file except in compliance with the License.
|
||
|
You may obtain a copy of the License at
|
||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||
|
|
||
|
Unless required by applicable law or agreed to in writing, software
|
||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||
|
See the License for the specific language governing permissions and
|
||
|
limitations under the License.
|
||
|
|
||
|
|
||
|
This example demonstrates a very simple use of the SevSeg library with a 4
|
||
|
digit display. It displays a counter that counts up, showing deci-seconds.
|
||
|
*/
|
||
|
|
||
|
#include "SevSeg.h"
|
||
|
SevSeg sevseg; //Instantiate a seven segment controller object
|
||
|
|
||
|
void setup() {
|
||
|
byte numDigits = 4;
|
||
|
byte digitPins[] = {2, 3, 4, 5};
|
||
|
byte segmentPins[] = {6, 7, 8, 9, 10, 11, 12, 13};
|
||
|
bool resistorsOnSegments = false; // 'false' means resistors are on digit pins
|
||
|
byte hardwareConfig = COMMON_CATHODE; // See README.md for options
|
||
|
bool updateWithDelays = false; // Default. Recommended
|
||
|
bool leadingZeros = false; // Use 'true' if you'd like to keep the leading zeros
|
||
|
|
||
|
sevseg.begin(hardwareConfig, numDigits, digitPins, segmentPins, resistorsOnSegments, updateWithDelays, leadingZeros);
|
||
|
sevseg.setBrightness(10);
|
||
|
pinMode(A5, INPUT_PULLUP);
|
||
|
pinMode(A1, INPUT_PULLUP);
|
||
|
// Serial.begin(9600); // debugging
|
||
|
}
|
||
|
|
||
|
int decPlaces = 3;
|
||
|
float lastReset = 0; // optional button reset - orange wire connected to A1, or programmable button on A5
|
||
|
|
||
|
void loop() {
|
||
|
unsigned long runMillis= millis();
|
||
|
float actualDays = runMillis/86400000.0;
|
||
|
float days = actualDays - lastReset;
|
||
|
sevseg.setNumber(days, decPlaces);
|
||
|
sevseg.refreshDisplay(); // Must run repeatedly
|
||
|
// Serial.println(actualDays,5); // debugging
|
||
|
// Serial.println(digitalRead(A1)); // debugging
|
||
|
if(!digitalRead(A1)){lastReset -= 0.001;}
|
||
|
// if(!digitalRead(A5)){lastReset = actualDays;}
|
||
|
// program A5 as decimal place changer
|
||
|
if(!digitalRead(A5)){
|
||
|
// if(decPlaces == 2){decPlaces = 3;}
|
||
|
// if(decPlaces == 3){decPlaces = 2;}
|
||
|
decPlaces = (decPlaces + 1)%2 + 2;
|
||
|
delay(250);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/// END ///
|