Restructured into a definitive format;

Updated keywords.txt;
Added library examples.
This commit is contained in:
rjbatista@gmail.com
2011-08-10 00:18:25 +00:00
parent 1b3265f0cc
commit f54360bd37
5 changed files with 160 additions and 75 deletions

View File

@@ -8,15 +8,20 @@ A library for interacting an arduino with a tm1638.
Includes:
- Helper methods for displaying numbers in decimal, hexadecimal and binary;
- Support for multiple chained tm1638; Reading
- simultaneous button presses.
- Support for multiple chained tm1638;
- Reading simultaneous button presses;
- Support for dimming the display and LEDs.
See: TM1638 Display/LED module at http://www.dealextreme.com/p/81873?r=68099021
USAGE NOTES
-----------
Just put the files on a TM1638 directory under "arduino/libraries" on your instalation
PROJECT HOME
------------
http://code.google.com/p/tm1638-library/
http://code.google.com/p/tm1638-library/

View File

@@ -0,0 +1,34 @@
/*
TM1638.h - Library for TM1638.
Copyright (C) 2011 Ricardo Batista <rjbatista at gmail dot com>
This program is free software: you can redistribute it and/or modify
it under the terms of the version 3 GNU General Public License as
published by the Free Software Foundation.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <TM1638.h>
// define a module on data pin 3, clock pin 2 and strobe pin 4
TM1638 module(3, 2, 4);
void setup() {
// display a hexadecimal number and set the left 4 dots
module.setDisplayToHexNumber(0x1234ABCD, 0xF0);
}
void loop() {
byte keys = module.getButtons();
// light the first 4 red LEDs and the last 4 green LEDs as the buttons are pressed
module.setLEDs(((keys & 0xF0) << 8) | (keys & 0xF));
}

View File

@@ -0,0 +1,101 @@
/*
TM1638.h - Library for TM1638.
Copyright (C) 2011 Ricardo Batista <rjbatista at gmail dot com>
This program is free software: you can redistribute it and/or modify
it under the terms of the version 3 GNU General Public License as
published by the Free Software Foundation.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "TM1638.h"
// hello segments for display
const byte hello[] = {
0b00000000, 0b01110110, 0b01111001, 0b00111000, 0b00111000, 0b00111111, 0b00000000, 0b00000000
};
// define the first module
TM1638 module1(3, 2, 4);
// to chain modules, use the same clk and data - just specify a different strobe pin
TM1638 module2(3, 2, 5);
unsigned long value = 0L;
boolean state = true;
void setup()
{
// display the hello segments on module 1
module1.setDisplay(hello);
// display the hello segments on module 2
module2.setDisplay(hello);
// light the lower 5 red LEDs and the top 5 green LEDs
module1.setLEDs(0b00011111 | 0b11111000 << 8);
// light the 3rd red LED
module2.setLED(TM1638_COLOR_RED, 3);
// light the 5th green LED
module2.setLED(TM1638_COLOR_GREEN, 5);
// light the 7th red and green LEDs
module2.setLED(TM1638_COLOR_RED | TM1638_COLOR_GREEN, 7);
}
void loop()
{
byte key1, key2;
// read the buttons from the first module
key1 = module1.getButtons();
// read the buttons from the second module
key2 = module2.getButtons();
// both pressed
if (key1 != 0 && key2 != 0) {
value = 0;
// set the display to 0 on both modules if they have buttons pressed simultaneously
module1.setDisplayToHexNumber(value, 0b10101010);
module2.setDisplayToDecNumber(value, 0b01010101);
} else {
// check the first module buttons
if (key1 != 0) {
// show the pressed buttons of the first module on its display
module2.setDisplayToBinNumber(key1, 0);
// and on the LEDs
module1.setLEDs(key1);
// check to see if it's the last button pressed
if (key1 & 128) {
// toggle the display state on/off
state = !state;
delay(200); // just wait for button up
}
// set the intensity and display state
module1.setupDisplay(state, key1 >> 1);
}
// check the second module buttons
if (key2 != 0) {
// just add it to the display value
value += key2;
// display it as an hexadecimal on the first module
module1.setDisplayToHexNumber(value, 0b10101010);
// and as a decimal on the second module
module2.setDisplayToDecNumber(value, 0b01010101);
// light the LEDs
module2.setLEDs(key2 << 8);
}
}
}

View File

@@ -6,20 +6,28 @@
# Datatypes (KEYWORD1)
#######################################
TM1638 KEYWORD1
TM1638 KEYWORD1
#######################################
# Methods and Functions (KEYWORD2)
#######################################
setSegments KEYWORD2
setLEDs KEYWORD2
getButtons KEYWORD2
sendCommand KEYWORD2
sendData KEYWORD2
send KEYWORD2
receive KEYWORD2
setupDisplay KEYWORD2
setDisplayToHexNumber KEYWORD2
setDisplayToDecNumber KEYWORD2
setDisplayToBinNumber KEYWORD2
setDisplayDigit KEYWORD2
setDisplay KEYWORD2
setLED KEYWORD2
setLEDs KEYWORD2
getButtons KEYWORD2
sendCommand KEYWORD2
sendData KEYWORD2
send KEYWORD2
receive KEYWORD2
#######################################
# Constants (LITERAL1)
#######################################
TM1638_COLOR_RED LITERAL1
TM1638_COLOR_GREEN LITERAL1

View File

@@ -1,63 +0,0 @@
#include "TM1638.h"
unsigned char hello[] = {
0b00000000, 0b01110110, 0b01111001, 0b00111000, 0b00111000, 0b00111111, 0b00000000, 0b00000000
};
TM1638 module1(2, 3, 4);
TM1638 module2(2, 3, 5);
unsigned long value = 0L;
boolean state = true;
void setup()
{
module1.setDisplay(hello);
module2.setDisplay(hello);
module1.setLEDs(0b00011111 | 0b11111000 << 8);
module2.setLED(TM1638_COLOR_RED, 3);
module2.setLED(TM1638_COLOR_GREEN, 5);
module2.setLED(TM1638_COLOR_RED | TM1638_COLOR_GREEN, 7);
}
void loop()
{
byte key1, key2;
key1 = module1.getButtons();
key2 = module2.getButtons();
// both pressed
if (key1 != 0 && key2 != 0) {
value = 0;
module1.setDisplayToHexNumber(value, 0b10101010);
module2.setDisplayToDecNumber(value, 0b01010101);
} else {
if (key1 != 0) {
value += key1;
module2.setDisplayToBinNumber(key1, 0);
module1.setLEDs(key1);
if (key1 & 128) {
state = !state;
delay(200); // just wait for button up
}
module1.setupDisplay(state, key1 >> 1);
}
if (key2 != 0) {
value += key2;
module1.setDisplayToHexNumber(value, 0b10101010);
module2.setDisplayToDecNumber(value, 0b01010101);
module2.setLEDs(key2 << 8);
}
}
}