splash screen and pulse working

Dependencies:   mbed

Committer:
raduschirila
Date:
Wed Jan 31 14:49:42 2018 +0000
Revision:
0:850d65a7d593
Child:
1:82127072abb8
working pulse thing with display splash screen;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
raduschirila 0:850d65a7d593 1 #include "mbed.h"
raduschirila 0:850d65a7d593 2
raduschirila 0:850d65a7d593 3
raduschirila 0:850d65a7d593 4 #define max7219_reg_noop 0x00
raduschirila 0:850d65a7d593 5 #define max7219_reg_digit0 0x01
raduschirila 0:850d65a7d593 6 #define max7219_reg_digit1 0x02
raduschirila 0:850d65a7d593 7 #define max7219_reg_digit2 0x03
raduschirila 0:850d65a7d593 8 #define max7219_reg_digit3 0x04
raduschirila 0:850d65a7d593 9 #define max7219_reg_digit4 0x05
raduschirila 0:850d65a7d593 10 #define max7219_reg_digit5 0x06
raduschirila 0:850d65a7d593 11 #define max7219_reg_digit6 0x07
raduschirila 0:850d65a7d593 12 #define max7219_reg_digit7 0x08
raduschirila 0:850d65a7d593 13 #define max7219_reg_decodeMode 0x09
raduschirila 0:850d65a7d593 14 #define max7219_reg_intensity 0x0a
raduschirila 0:850d65a7d593 15 #define max7219_reg_scanLimit 0x0b
raduschirila 0:850d65a7d593 16 #define max7219_reg_shutdown 0x0c
raduschirila 0:850d65a7d593 17 #define max7219_reg_displayTest 0x0f
raduschirila 0:850d65a7d593 18
raduschirila 0:850d65a7d593 19
raduschirila 0:850d65a7d593 20
raduschirila 0:850d65a7d593 21
raduschirila 0:850d65a7d593 22
raduschirila 0:850d65a7d593 23 Ticker pulse;
raduschirila 0:850d65a7d593 24 AnalogIn pulse_in(PTB0);
raduschirila 0:850d65a7d593 25 AnalogOut o(PTE30);
raduschirila 0:850d65a7d593 26 DigitalOut led(LED1);
raduschirila 0:850d65a7d593 27 void get_pulse()
raduschirila 0:850d65a7d593 28 {
raduschirila 0:850d65a7d593 29 o=pulse_in;
raduschirila 0:850d65a7d593 30 }
raduschirila 0:850d65a7d593 31
raduschirila 0:850d65a7d593 32
raduschirila 0:850d65a7d593 33
raduschirila 0:850d65a7d593 34
raduschirila 0:850d65a7d593 35 #define LOW 0
raduschirila 0:850d65a7d593 36 #define HIGH 1
raduschirila 0:850d65a7d593 37
raduschirila 0:850d65a7d593 38 SPI max72_spi(PTD2, NC, PTD1);
raduschirila 0:850d65a7d593 39 DigitalOut load(PTD0); //will provide the load signal
raduschirila 0:850d65a7d593 40
raduschirila 0:850d65a7d593 41
raduschirila 0:850d65a7d593 42 char heart[8] = {0x00,0x36,0x7f,0x7f,0x3e,0x1c,0x08,0x00};
raduschirila 0:850d65a7d593 43 char pattern_square[8] = { 0xff, 0x81,0x81,0x81,0x81,0x81,0x81,0xff};
raduschirila 0:850d65a7d593 44 char pattern_star[8] = { 0x04, 0x15, 0x0e, 0x1f, 0x0e, 0x15, 0x04, 0x00};
raduschirila 0:850d65a7d593 45
raduschirila 0:850d65a7d593 46
raduschirila 0:850d65a7d593 47 /*
raduschirila 0:850d65a7d593 48 Write to the maxim via SPI
raduschirila 0:850d65a7d593 49 args register and the column data
raduschirila 0:850d65a7d593 50 */
raduschirila 0:850d65a7d593 51 void write_to_max( int reg, int col)
raduschirila 0:850d65a7d593 52 {
raduschirila 0:850d65a7d593 53 load = LOW; // begin
raduschirila 0:850d65a7d593 54 max72_spi.write(reg); // specify register
raduschirila 0:850d65a7d593 55 max72_spi.write(col); // put data
raduschirila 0:850d65a7d593 56 load = HIGH; // make sure data is loaded (on rising edge of LOAD/CS)
raduschirila 0:850d65a7d593 57 }
raduschirila 0:850d65a7d593 58
raduschirila 0:850d65a7d593 59 //writes 8 bytes to the display
raduschirila 0:850d65a7d593 60 void pattern_to_display(char *testdata){
raduschirila 0:850d65a7d593 61 int cdata;
raduschirila 0:850d65a7d593 62 for(int idx = 0; idx <= 7; idx++) {
raduschirila 0:850d65a7d593 63 cdata = testdata[idx];
raduschirila 0:850d65a7d593 64 write_to_max(idx+1,cdata);
raduschirila 0:850d65a7d593 65 }
raduschirila 0:850d65a7d593 66 }
raduschirila 0:850d65a7d593 67
raduschirila 0:850d65a7d593 68
raduschirila 0:850d65a7d593 69 void setup_dot_matrix ()
raduschirila 0:850d65a7d593 70 {
raduschirila 0:850d65a7d593 71 // initiation of the max 7219
raduschirila 0:850d65a7d593 72 // SPI setup: 8 bits, mode 0
raduschirila 0:850d65a7d593 73 max72_spi.format(8, 0);
raduschirila 0:850d65a7d593 74
raduschirila 0:850d65a7d593 75
raduschirila 0:850d65a7d593 76
raduschirila 0:850d65a7d593 77 max72_spi.frequency(100000); //down to 100khx easier to scope ;-)
raduschirila 0:850d65a7d593 78
raduschirila 0:850d65a7d593 79
raduschirila 0:850d65a7d593 80 write_to_max(max7219_reg_scanLimit, 0x07);
raduschirila 0:850d65a7d593 81 write_to_max(max7219_reg_decodeMode, 0x00); // using an led matrix (not digits)
raduschirila 0:850d65a7d593 82 write_to_max(max7219_reg_shutdown, 0x01); // not in shutdown mode
raduschirila 0:850d65a7d593 83 write_to_max(max7219_reg_displayTest, 0x00); // no display test
raduschirila 0:850d65a7d593 84 for (int e=1; e<=8; e++) { // empty registers, turn all LEDs off
raduschirila 0:850d65a7d593 85 write_to_max(e,0);
raduschirila 0:850d65a7d593 86 }
raduschirila 0:850d65a7d593 87 // maxAll(max7219_reg_intensity, 0x0f & 0x0f); // the first 0x0f is the value you can set
raduschirila 0:850d65a7d593 88 write_to_max(max7219_reg_intensity, 0x08);
raduschirila 0:850d65a7d593 89
raduschirila 0:850d65a7d593 90 }
raduschirila 0:850d65a7d593 91
raduschirila 0:850d65a7d593 92 void clear(){
raduschirila 0:850d65a7d593 93 for (int e=1; e<=8; e++) { // empty registers, turn all LEDs off
raduschirila 0:850d65a7d593 94 write_to_max(e,0);
raduschirila 0:850d65a7d593 95 }
raduschirila 0:850d65a7d593 96 }
raduschirila 0:850d65a7d593 97 int main()
raduschirila 0:850d65a7d593 98 {
raduschirila 0:850d65a7d593 99 pulse.attach(&get_pulse,0.125);
raduschirila 0:850d65a7d593 100 setup_dot_matrix (); /* setup matric */
raduschirila 0:850d65a7d593 101 while(1){
raduschirila 0:850d65a7d593 102 //da_star();
raduschirila 0:850d65a7d593 103 pattern_to_display(heart);
raduschirila 0:850d65a7d593 104 wait_ms(1000);
raduschirila 0:850d65a7d593 105 heart[7]=0x01;heart[0]=0x01;
raduschirila 0:850d65a7d593 106 for(int i=1;i<=8;++i)
raduschirila 0:850d65a7d593 107 {
raduschirila 0:850d65a7d593 108 pattern_to_display(heart);
raduschirila 0:850d65a7d593 109 wait(0.2);
raduschirila 0:850d65a7d593 110 heart[7]<<=1;
raduschirila 0:850d65a7d593 111 heart[7]|=1;
raduschirila 0:850d65a7d593 112 heart[0]=heart[7];
raduschirila 0:850d65a7d593 113 }
raduschirila 0:850d65a7d593 114 for(int i=1;i<=6;++i)
raduschirila 0:850d65a7d593 115 {
raduschirila 0:850d65a7d593 116 heart[i]=~heart[i];
raduschirila 0:850d65a7d593 117 }
raduschirila 0:850d65a7d593 118 pattern_to_display(heart);
raduschirila 0:850d65a7d593 119 wait(1.6);
raduschirila 0:850d65a7d593 120 clear();
raduschirila 0:850d65a7d593 121 }
raduschirila 0:850d65a7d593 122 }