splash screen and pulse working

Dependencies:   mbed

Committer:
raduschirila
Date:
Fri Feb 02 11:54:14 2018 +0000
Revision:
1:82127072abb8
Parent:
0:850d65a7d593
processed pulse (non-PID version) ready for display. Need more work on which bits to change to make the display obey. Might need to rotate everything 90deg to make it easier in terms of mcu processing

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
raduschirila 0:850d65a7d593 44
raduschirila 1:82127072abb8 45 //DISPLAY FUNCTIONS DO NOT TOUCH
raduschirila 1:82127072abb8 46
raduschirila 0:850d65a7d593 47 void write_to_max( int reg, int col)
raduschirila 0:850d65a7d593 48 {
raduschirila 0:850d65a7d593 49 load = LOW; // begin
raduschirila 0:850d65a7d593 50 max72_spi.write(reg); // specify register
raduschirila 0:850d65a7d593 51 max72_spi.write(col); // put data
raduschirila 0:850d65a7d593 52 load = HIGH; // make sure data is loaded (on rising edge of LOAD/CS)
raduschirila 0:850d65a7d593 53 }
raduschirila 0:850d65a7d593 54
raduschirila 0:850d65a7d593 55 //writes 8 bytes to the display
raduschirila 0:850d65a7d593 56 void pattern_to_display(char *testdata){
raduschirila 0:850d65a7d593 57 int cdata;
raduschirila 0:850d65a7d593 58 for(int idx = 0; idx <= 7; idx++) {
raduschirila 0:850d65a7d593 59 cdata = testdata[idx];
raduschirila 0:850d65a7d593 60 write_to_max(idx+1,cdata);
raduschirila 0:850d65a7d593 61 }
raduschirila 0:850d65a7d593 62 }
raduschirila 0:850d65a7d593 63
raduschirila 0:850d65a7d593 64
raduschirila 0:850d65a7d593 65 void setup_dot_matrix ()
raduschirila 0:850d65a7d593 66 {
raduschirila 0:850d65a7d593 67 // initiation of the max 7219
raduschirila 0:850d65a7d593 68 // SPI setup: 8 bits, mode 0
raduschirila 0:850d65a7d593 69 max72_spi.format(8, 0);
raduschirila 0:850d65a7d593 70
raduschirila 0:850d65a7d593 71
raduschirila 0:850d65a7d593 72
raduschirila 0:850d65a7d593 73 max72_spi.frequency(100000); //down to 100khx easier to scope ;-)
raduschirila 0:850d65a7d593 74
raduschirila 0:850d65a7d593 75
raduschirila 0:850d65a7d593 76 write_to_max(max7219_reg_scanLimit, 0x07);
raduschirila 0:850d65a7d593 77 write_to_max(max7219_reg_decodeMode, 0x00); // using an led matrix (not digits)
raduschirila 0:850d65a7d593 78 write_to_max(max7219_reg_shutdown, 0x01); // not in shutdown mode
raduschirila 0:850d65a7d593 79 write_to_max(max7219_reg_displayTest, 0x00); // no display test
raduschirila 0:850d65a7d593 80 for (int e=1; e<=8; e++) { // empty registers, turn all LEDs off
raduschirila 0:850d65a7d593 81 write_to_max(e,0);
raduschirila 0:850d65a7d593 82 }
raduschirila 0:850d65a7d593 83 // maxAll(max7219_reg_intensity, 0x0f & 0x0f); // the first 0x0f is the value you can set
raduschirila 0:850d65a7d593 84 write_to_max(max7219_reg_intensity, 0x08);
raduschirila 0:850d65a7d593 85
raduschirila 0:850d65a7d593 86 }
raduschirila 0:850d65a7d593 87
raduschirila 0:850d65a7d593 88 void clear(){
raduschirila 0:850d65a7d593 89 for (int e=1; e<=8; e++) { // empty registers, turn all LEDs off
raduschirila 0:850d65a7d593 90 write_to_max(e,0);
raduschirila 0:850d65a7d593 91 }
raduschirila 0:850d65a7d593 92 }
raduschirila 1:82127072abb8 93
raduschirila 1:82127072abb8 94 //END OF DISPLAY FUNCTIONS
raduschirila 1:82127072abb8 95
raduschirila 1:82127072abb8 96 void splash_screen()
raduschirila 0:850d65a7d593 97 {
raduschirila 0:850d65a7d593 98 setup_dot_matrix (); /* setup matric */
raduschirila 0:850d65a7d593 99 pattern_to_display(heart);
raduschirila 0:850d65a7d593 100 wait_ms(1000);
raduschirila 0:850d65a7d593 101 heart[7]=0x01;heart[0]=0x01;
raduschirila 0:850d65a7d593 102 for(int i=1;i<=8;++i)
raduschirila 0:850d65a7d593 103 {
raduschirila 0:850d65a7d593 104 pattern_to_display(heart);
raduschirila 0:850d65a7d593 105 wait(0.2);
raduschirila 0:850d65a7d593 106 heart[7]<<=1;
raduschirila 0:850d65a7d593 107 heart[7]|=1;
raduschirila 0:850d65a7d593 108 heart[0]=heart[7];
raduschirila 0:850d65a7d593 109 }
raduschirila 0:850d65a7d593 110 for(int i=1;i<=6;++i)
raduschirila 0:850d65a7d593 111 {
raduschirila 0:850d65a7d593 112 heart[i]=~heart[i];
raduschirila 0:850d65a7d593 113 }
raduschirila 0:850d65a7d593 114 pattern_to_display(heart);
raduschirila 0:850d65a7d593 115 wait(1.6);
raduschirila 0:850d65a7d593 116 clear();
raduschirila 0:850d65a7d593 117 }
raduschirila 1:82127072abb8 118
raduschirila 1:82127072abb8 119 int main()
raduschirila 1:82127072abb8 120 {
raduschirila 1:82127072abb8 121 pulse.attach(&get_pulse,0.125);
raduschirila 1:82127072abb8 122 splash_screen();
raduschirila 1:82127072abb8 123 while(1)
raduschirila 1:82127072abb8 124 {
raduschirila 1:82127072abb8 125 }
raduschirila 1:82127072abb8 126 }