Components and supplies
Shift register - TPIC6B595
Apps and platforms
Arduino IDE 2.0 (beta)
Project description
Code
Sample code
cpp
Sample code for TPIC6B595 and DM134B
1// DM134B test program using hardware SPI (or ShiftOut) 2// This displays a seconds counter that counts from 0-999 seconds then resets. 3// If you added a button and relevant code you could use this as a stopwatch. 4// SoftPWM library used to avoid conflicts with timers and SPI when using hardware PWM 5// the SoftPWM library allows the display brightness to be adjusted in software. 6// This circuit will draw approx 600mA at full brightness displaying 8888 (21.5mA per segment) 7// If high brightness not required either back off using onboard brightness pot or set to max 4 8// brightness if using software control to adjust brightness through PWM. This will reduce power useage. 9// For example if using for a clock you could automatically dim the display at night. 10 11// 7-segment digits 0-9 12// {Q0, Q1, Q2, Q3, Q4, Q5, Q6, Q7} --> {g, f, e, d, c, b, a, DP} 13 14#include <SPI.h> 15#include <SoftPWM.h> 16 17int dm134_clock = 13; 18int dm134_latch = 10; // DM134B datasheet says active low but seems to be active high (like a '595)? 19int dm134_data = 11; 20int dm134_OE = 9; // output enable; Active LOW. Can be used to control brightness with PWM. 21 22int brightness = 5; // set display brightness. 1-5 23int brt = 0; // value for storing reversed PWM percentage 24 25long int cnt = 0; // counter initial value = 0 26unsigned long previousMillis = 0; 27const long interval = 10; 28 29byte ssddigits[10] = // array without decimal points on 30{ 31 B01111110, // 0 32 B00001100, // 1 33 B10110110, // 2 34 B10011110, // 3 35 B11001100, // 4 36 B11011010, // 5 37 B11111010, // 6 38 B01001110, // 7 39 B11111110, // 8 40 B11011110, // 9 41}; 42 43byte ssddigitsDP[10] = // array with decimal points on 44{ 45 B01111111, // 0 46 B00001101, // 1 47 B10110111, // 2 48 B10011111, // 3 49 B11001101, // 4 50 B11011011, // 5 51 B11111011, // 6 52 B01001111, // 7 53 B11111111, // 8 54 B11011111, // 9 55}; 56 57void setup() 58{ 59 60 pinMode (dm134_clock, OUTPUT); 61 pinMode (dm134_latch, OUTPUT); 62 pinMode (dm134_data, OUTPUT); 63 pinMode (dm134_OE,OUTPUT); 64 digitalWrite(dm134_OE,LOW); // enable output of DM134B. 65 setBrt(); 66 SoftPWMBegin(); 67 SoftPWMSet(9, 0); // init software PWM on pin 9. This pulses the DM134 OE pin on and off to control brightness. 68 SoftPWMSetPercent(9, brt); 69 70} 71 72void setBrt() // this changes the DM134 brightness logarithmic reversed scale to a more linear one 73 74{ 75 if (brightness == 1) 76 brt = 90; 77 78 else if (brightness == 2) 79 brt = 75; 80 81 else if (brightness == 3) 82 brt = 50; 83 84 else if (brightness == 4) 85 brt = 30; 86 87 else if (brightness == 5) 88 brt = 0; 89} 90 91void loop() 92{ 93 unsigned long currentMillis = millis(); 94 95 if (currentMillis - previousMillis >= interval) 96 { 97 previousMillis = currentMillis; 98 cnt++; 99 } 100 101 if (cnt == 9999) 102 { 103 cnt = 0; 104 } 105 106 107 108 displayNum(); 109} 110 111void displayNum() 112{ 113 114//long int num = analogRead(0); 115//long int num = 1234; 116long int num = cnt; 117 118// get digit 0 119int dig3 = num % 10; // ones 120// get digit 1 121int dig2 = (num / 10) % 10; // tens 122// get digit 2 123int dig1 = (num / 100) % 10; // hundreds 124// get digit 3 125int dig0 = (num / 1000) % 10; // thousands 126 127SPI.beginTransaction(SPISettings(8000000, LSBFIRST, SPI_MODE0)); 128digitalWrite(dm134_latch,LOW); 129SPI.transfer(ssddigits[dig3]); 130SPI.transfer(ssddigitsDP[dig2]); 131SPI.transfer(ssddigits[dig1]); 132SPI.transfer(ssddigits[dig0]); 133digitalWrite(dm134_latch,HIGH); 134SPI.endTransaction(); 135 136/* 137// shift out digits 138digitalWrite(dm134_latch,LOW); 139shiftOut(dm134_data, dm134_clock, LSBFIRST, ssddigits[dig3]); 140shiftOut(dm134_data, dm134_clock, LSBFIRST, ssddigits[dig2]); 141shiftOut(dm134_data, dm134_clock, LSBFIRST, ssddigitsDP[dig1]); 142shiftOut(dm134_data, dm134_clock, LSBFIRST, ssddigits[dig0]); 143//shiftOut(dm134_data, dm134_clock, LSBFIRST, B00000001); // DP test 144//shiftOut(dm134_data, dm134_clock, LSBFIRST, B00000001); // DP test 145digitalWrite(dm134_latch,HIGH); 146 147*/ 148 149}
Documentation
Datasheet for KW-104S
Datasheet for Wamco's range of filament displays
https://www.wamcoinc.com/assets/pdf/Display%20Catalog.pdf
Comments
Only logged in users can leave comments
adrian-smith31
0 Followers
•0 Projects
Table of contents
Intro
0
0