Created
April 27, 2014 21:03
-
-
Save bassdread/11355648 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Author:Chris Hannam | |
// This library is free software; you can redistribute it and/or | |
// modify it under the terms of the GNU Lesser General Public | |
// License as published by the Free Software Foundation; either | |
// version 2.1 of the License, or (at your option) any later version. | |
// | |
// This library is distributed in the hope that it will be useful, | |
// but WITHOUT ANY WARRANTY; without even the implied warranty of | |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
// Lesser General Public License for more details. | |
// | |
// You should have received a copy of the GNU Lesser General Public | |
// License along with this library; if not, write to the Free Software | |
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
// uses https://github.com/reeedstudio/libraries/tree/master/DigitalTube | |
#include "TM1637.h" | |
#define CLK A4//pins definitions for TM1637 and can be changed to other ports | |
#define DIO A5 | |
TM1637 tm1637(CLK,DIO); | |
String inputString = ""; // a string to hold incoming data | |
boolean stringComplete = false; // whether the string is complete | |
void setup() | |
{ | |
tm1637.init(); | |
tm1637.set(BRIGHT_TYPICAL);//BRIGHT_TYPICAL = 2,BRIGHT_DARKEST = 0,BRIGHTEST = 7; | |
Serial.begin(9600); | |
} | |
void loop() | |
{ | |
//tm1637.point(POINT_ON); | |
if (stringComplete) { | |
tm1637.clearDisplay(); | |
inputString.replace("\n",""); | |
int numbers = inputString.length(); | |
if (numbers == 1) { | |
int f1 = inputString.substring(0,1).toInt(); | |
tm1637.display(3,f1); | |
} | |
if (numbers == 2) { | |
int f1 = inputString.substring(0,1).toInt(); | |
int f2 = inputString.substring(1,2).toInt(); | |
tm1637.display(3,f2); | |
tm1637.display(2,f1); | |
} | |
if (numbers == 3) { | |
int f1 = inputString.substring(0,1).toInt(); | |
int f2 = inputString.substring(1,2).toInt(); | |
int f3 = inputString.substring(2,3).toInt(); | |
tm1637.display(3,f3); | |
tm1637.display(2,f2); | |
tm1637.display(1,f1); | |
} | |
if (numbers == 4) { | |
int f1 = inputString.substring(0,1).toInt(); | |
int f2 = inputString.substring(1,2).toInt(); | |
int f3 = inputString.substring(2,3).toInt(); | |
int f4 = inputString.substring(3,4).toInt(); | |
tm1637.display(3,f4); | |
tm1637.display(2,f3); | |
tm1637.display(1,f2); | |
tm1637.display(0,f1); | |
} | |
} | |
delay(500); | |
} | |
void serialEvent() { | |
while (Serial.available()) { | |
// get the new byte: | |
char inChar = (char)Serial.read(); | |
// add it to the inputString: | |
inputString += inChar; | |
// if the incoming character is a newline, set a flag | |
// so the main loop can do something about it: | |
if (inChar == '\n') { | |
stringComplete = true; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment