#include <SPI.h>
//13=clock
//11=data
//10=latch
//MSB
int font [125] = //numbers stored here, int because of 16-bit size, unsigned char won't work
{ //Position, Character
// 0B (null) M L K J I H G2, G1 F E D C B A DOT
0B0001100001111110, // 0 0
0B0000000000001100, // 1 1
0B0000000110110110, // 2 2
0B0000000110011110, // 3 3
0B0000000111001100, // 4 4
0B0000000111011010, // 5 5
0B0000000111111010, // 6 6
0B0000000000001110, // 7 7
0B0000000111111110, // 8 8
0B0000000111011110, // 9 9
0B0000000000000000, // 10 \n
0B0000000000000000, // 11
0B0000000000000000, // 12
0B0000000000000000, // 13 \r
0B0000000000000000, // 14 \p
0B0000000000000000, // 15
0B0000000000000000, // 16
0B0000000000000000, // 17
0B0000000000000000, // 18
0B0000000000000000, // 19
0B0000000000000000, // 20
0B0000000000000000, // 21
0B0000000000000000, // 22
0B0000000000000000, // 23
0B0000000000000000, // 24
0B0000000000000000, // 25
0B0000000000000000, // 26
0B0000000000000000, // 27 /esc
0B0000000000000000, // 28
0B0000000000000000, // 29
0B0000000000000000, // 30
0B0000000000000000, // 31
0B0000000000000000, // 32 "space"
0B0000000000000000, // 33 !
0B0000000000000000, // 34
0B0000000000000000, // 35
0B0000000000000000, // 36
0B0000000000000000, // 37
0B0000000000000000, // 38
0B0000000000000000, // 39
0B0000000000000000, // 40
0B0000000000000000, // 41
0B0000000000000000, // 42
0B0000000000000000, // 43
0B0000000000000000, // 44
0B0000000110000000, // 45 -(minus)
0B0000000000000000, // 46
0B0000000000000000, // 47
0B0001100001111110, // 48 0
0B0000000000001100, // 49 1
0B0000000110110110, // 50 2
0B0000000110011110, // 51 3
0B0000000111001100, // 52 4
0B0000000111011010, // 53 5
0B0000000111111010, // 54 6
0B0000000000001110, // 55 7
0B0000000111111110, // 56 8
0B0000000111011110, // 57 9
0B0000000000000000, // 58 :
0B0000000000000000, // 59
0B0000000000000000, // 60
0B0000000110010000, // 61 =
0B0000000000000000, // 62
0B0000000000000000, // 63
0B0000000000000000, // 64
0B0000000111101110, // 65 A
0B0010010100011110, // 66 0B
0B0000000001110010, // 67 C
0B0010010000011110, // 68 D
0B0000000011110010, // 69 E
0B0000000011100010, // 70 F
0B0000000101111010, // 71 G
0B0000000111101100, // 72 H
0B0010010000010010, // 73 I
0B0000000000111100, // 74 J
0B0100100011100000, // 75 K
0B0000000001110000, // 76 L
0B0000101001101100, // 77 M
0B0100001001101100, // 78 N
0B0000000001111110, // 79 O
0B0000000111100110, // 80 P
0B0100000001111110, // 81 Q
0B0100000111100110, // 82 R
0B0000000111011010, // 83 S
0B0010010000000010, // 84 T
0B0000000001111100, // 85 U
0B0001100001100000, // 86 V
0B0101000001101100, // 87 W
0B0101101000000000, // 88 X
0B0000000000000000, // 89 Y
0B0000000000000000, // 90 Z
0B0000000001110010, // 91 [
0B0000000000000000, // 92
0B0000000000011110, // 93 ]
0B0000000000000000, // 94
0B0000000000010000, // 95 _
0B0000000000000000, // 96
0B0000000010111110, // 97 a
0B0000000011111000, // 98 b
0B0000000010110000, // 99 c
0B0000000010111100, // 100 d
0B0000000011110110, // 101 e
0B0000000000000000, // 102 f
0B0000000000000000, // 103 g
0B0000000011101000, // 104 h
0B0000000000000000, // 105 i
0B0000000000000000, // 106 j
0B0000000000000000, // 107 k
0B0000000000000000, // 108 l
0B0000000000000000, // 109 m
0B0000000000000000, // 110 n
0B0000000010111000, // 111 o
0B0000000000000000, // 112 p
0B0000000000000000, // 113 q
0B0000000000000000, // 114 r
0B0000000000000000, // 115 s
0B0000000000000000, // 116 t
0B0000000000111000, // 117 u
0B0000000000000000, // 118 v
0B0000000000000000, // 119 w
0B0000000000000000, // 120 x
0B0000000000000000, // 121 y
0B0000000000000000, // 122 z
0B0000000000000000, // 123
0B0000000000000000, // 124
};
void setup (void)
{
SPI.begin ();
}
void loop (void)
{
digitalWrite(SS, HIGH); // SS is pin 10
SPI.transfer(1);
SPI.transfer16(font[millis() / 1000 % 10]);
digitalWrite(SS, LOW);
digitalWrite(SS, HIGH); // SS is pin 10
SPI.transfer(2);
SPI.transfer16(font[millis() / 10000 % 10]);
digitalWrite(SS, LOW);
} // end of loop
dim int id[]={0,1,2}
dim float sales[]={500.00,1000.00,800,00}
dim string name[]={
"Don","John","Ron"}
...
// part of source code
if (sales[i]<sales[i+1{) {
tmpInt=id[i+1]
id[i+1]=id[i]
id[i]=tmpInt
TmpString=name[id+1]
name[id+1]=name[i]
name[i]=tmpString
TmpFloat=sales[i+1]
sales[i+1]=sales[i]
sales[i]=temprecord
}
dim struct salesrecord {
int id
float sales
string name
}
dim salesrecord salesman[]
dim salesrecord temprecord
...
// part of source code
If (salesman.sales[i]<salesman.sales[i+1]){
temprecord=salesman[i+1]
salesman[i+1]=salesman[i]
salesman[i]=temprecord
}
#include "FontMap14Segment.h"
int dataPin = 2; // ic: 14, ser_in Define which pins will be used for the Shift Register control
int latchPin = 3; // ic:12 silkscreen numbers!
int clockPin = 4;
unsigned char displayPointer = 0; // for interrupt use...
int buffer1[2]; //16 bits for each digit
int backbuffer[2]; // Spare screen for drawing on
int power[16] = {1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768};
ISR(TIMER1_COMPA_vect) // timer compare interrupt service routine, called every now and then, outside of loop
{
if (TIFR2) // Make sure its the timer interrupt.
{
setcolumn(displayPointer); //column scanning
setdata(buffer1[displayPointer]);
PORTD = (1 << PORTD3);
PORTD = (0 << PORTD3);
//digitalWrite(latchPin ,HIGH);
//digitalWrite(latchPin , LOW ); // STORECLOCK
if (++displayPointer == 2) //4 because there are two digits, each need 2x8 bits
{ displayPointer = 0;
} // 32 LED row sections in total
}
TIFR2 = 0; // Clear timer 2 interrupt flag
}
void setcolumn(int col) //loop that takes care of column scanning
{
signed char pos;
for (pos = 16; pos > -1; pos--) //was pos=32, but again, only 4 columns now so pos=4
{
if (col == pos)
{
PORTD = (0 << PORTD2); //digitalWrite(dataPin ,HIGH); //swapping these reversed unlit-lit digits
}
else
{
PORTD = (1 << PORTD2); //digitalWrite(dataPin ,LOW);
}
digitalWrite(clockPin , HIGH);
digitalWrite(clockPin , LOW);
}
}
void setdata(int dat) {
int pos;
for (pos = 0; pos < 16; pos++)
{
if (dat & 32768) //these dat were 128, but changed them to 16 as 16=128/8
{
dat -= 32768;
PORTD = (1 << PORTD2); //digitalWrite(dataPin ,HIGH); //swapping these caused whole screen to be reversed for lit-unlit segments
}
else
{
PORTD = (0 << PORTD2); //digitalWrite(dataPin ,LOW);} // PIN1 DATA pin
}
dat = dat * 2;
digitalWrite(clockPin , HIGH);
digitalWrite(clockPin , LOW);
}
}
void clr() //clear
{
int addr;
for (addr = 0; addr < 2; addr++) // Empty display buffer, reduced from 32 to 4
backbuffer[addr] = 0;
}
void Blit() //transfers data between display buffer to screen buffer
{
int addr = 0;
noInterrupts(); // disable all interrupts during setup
for (addr = 0; addr < 2; addr ++) //here also changed 32 to 4
{
buffer1[addr] = backbuffer[addr]; // put all data from display buffer to screen buffer
}
interrupts(); // enable all interrupts
}
void pixel(signed char x, signed char y, int cond)
{
int pix, msk;
if (x < 0 || y < 0) return; // outside drawing limits negative
if (x > 1 || y > 15) return; // outside drawing limits positive
pix = power[y];
msk = backbuffer[x]; // get exsisting data
if (cond == 2)
pix ^= msk; // XOR data to screen
if (cond == 1)
{
pix = ~pix;
pix &= msk; // AND data to screen
}
if (cond == 0)
pix |= msk; // OR data to screen
backbuffer[x] = pix; // apply changes
}
void charput(int ch, signed char x, signed char y)
{
signed char y1;
int disp;
int disp2;
disp = font[ch]; //look data from fontmap,
for (y1 = 15; y1 > 0; y1--) // eight pixels
{
disp2 = disp & power[y1];
if (disp2 > 0)
{
pixel(x , y + y1, 0); // OR the pixel to the display buffer
}
}
}
void strput(const char* ch, signed char x, signed char y)
{
int addr;
while (*ch )
{
charput(*ch++, x, y); // write a string to the display buffer
x += 1;
}
}
void setup() //setup runs once
{
Serial.begin(9600);
noInterrupts(); // disable all interrupts during setup
DDRD = DDRD | B11111100; //port registers used to set pin directions
TCCR1A = 0;
TCCR1B = 0;
TCNT1 = 0;
OCR1A = 260; // compare match register value, was 31 for matrix (1920hz= 60hzx*32) but for now there's only 4 columns so: 4*60hz=240hz; 16mhz/256/240=260
TCCR1B |= (1 << WGM12); // CTC mode, free-running, clear on match
TCCR1B |= (0 << CS10); // 256 prescaler
TCCR1B |= (0 << CS11); // 256 prescaler
TCCR1B |= (1 << CS12); // 256 prescaler
TIMSK1 |= (1 << OCIE1A); // enable timer compare interrupt
interrupts(); // enable all interrupts
} // End main
void loop() //just sitting here
{
for (int i = 3; i > -30; i--)
{
clr();
strput("HACKLAB__MIKKELI", i, 0);
Blit();
delay(500);
}
}
int pos;
for (pos = columns; pos > -1; pos--)
{
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?