Code Monkey home page Code Monkey logo

attiny-tm1638-library's Introduction

TM1638 Library

This is tinyAVR (ATtiny13, ATtiny25, ATtiny45, ATtiny85, and other) library for LED controller modules based on TM1638 chip.

alt text

Modules based on TM1638 provide three signal connections (CLK, STB and DIO) and two power connections (VCC and GND). Signal pins can be connected to any pair of digital pins of the AVR chip. Signal pins configuration is defined at the top of library header file, where it can be modifed.

Key Features

This library has the following features:

  • display digits & dots,
  • display raw segments,
  • display LEDs,
  • display on/off,
  • brightness control,
  • scan keys,
  • software I2C.

The communication part has been inspired by projects:

Example Code

This example code demonstrates basic usage of the library:

#include <stdint.h>
#include <util/delay.h>
#include "tm1638.h"

int
main(void)
{
	uint8_t j, i = 0;

	/* setup */
	TM1638_init(1/*enable*/, 7/*brighness*/);

	/* loop */
	while (1) {
		for (j = 0; j < 8; ++j) {
			TM1638_display_digit(j/*position*/,
				(i + j) % 0x10/*digit*/,
				!!(i % 0x02)/*dot*/);
		}
		_delay_ms(100);
		i++;
	}
}

API Documentation (tm1638.h)

/**
 * Initialize TM1638 LED controller.
 * Clock pin (TM1638_CLK_PIN), strobe pin (TM1638_STB_PIN)
 * and data pin (TM1638_DIO_PIN) are defined at the top of this file.
 */
void TM1638_init(const uint8_t enable, const uint8_t brightness);

/**
 * Set display brightness.
 * Min brightness: 0
 * Max brightness: 7
 */
void TM1638_set_brightness(const uint8_t brightness);

/**
 * Turn display on/off.
 * value: 1 - on, 0 - off
 */
void TM1638_enable(const uint8_t value);

/**
 * Display raw segments at position (0x00..0x07)
 * 
 *      bits:
 *        -- 0 -- 
 *       |       |
 *       5       1
 *       |       |
 *        -- 6 -- 
 *       |       |
 *       4       2
 *       |       |
 *        -- 3 -- *7
 *
 * Example segment configurations:
 * - for character 'H', segments=0b01110110
 * - for character '-', segments=0b01000000
 * - etc.
 */
void TM1638_display_segments(const uint8_t position, const uint8_t segments);

/**
 * Clear all display segments (including dots).
 */
void TM1638_clear_segments(void);

/**
 * Display digit ('0'..'9') with optional dot at position (0x00..0x07)
 */ 
void TM1638_display_digit(const uint8_t position, const uint8_t digit, const uint8_t dot);

/**
 * Light LED at position (0x00..0x07)
 * value: 1 - on, 0 - off
 */ 
void TM1638_set_led(const uint8_t position, const uint8_t value);

/**
 * Clear all leds.
 */
void TM1638_clear_leds(void);

/**
 * Scan keys.
 */
uint8_t TM1638_scan_keys(void);

attiny-tm1638-library's People

Contributors

lpodkalicki avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.