sup monica

Dependencies:   mbed

Fork of EDP2_display by EDP2

Committer:
raduschirila
Date:
Wed Feb 14 23:27:29 2018 +0000
Revision:
2:281d8c268a8e
Parent:
1:82127072abb8
sup

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 2:281d8c268a8e 22 Serial pc(USBTX, USBRX); // tx, rx this is for the data to be sent via the usb port to the computer
raduschirila 0:850d65a7d593 23 Ticker pulse;
raduschirila 0:850d65a7d593 24 AnalogIn pulse_in(PTB0);
raduschirila 0:850d65a7d593 25 AnalogOut o(PTE30);
raduschirila 2:281d8c268a8e 26 DigitalOut led(PTD5);
raduschirila 2:281d8c268a8e 27 float xi,ypast,y,sum;//absolute max
raduschirila 2:281d8c268a8e 28 float alpha=0.8;
raduschirila 2:281d8c268a8e 29 int no;
raduschirila 2:281d8c268a8e 30 bool first=true;
raduschirila 0:850d65a7d593 31 void get_pulse()
raduschirila 0:850d65a7d593 32 {
raduschirila 2:281d8c268a8e 33 xi=(float)pulse_in;
raduschirila 2:281d8c268a8e 34 //noise reduction algorithm
raduschirila 2:281d8c268a8e 35 if(!first)//noise filtering procedure
raduschirila 2:281d8c268a8e 36 {
raduschirila 2:281d8c268a8e 37 y=alpha*xi+ (1-alpha)*ypast;
raduschirila 2:281d8c268a8e 38 }
raduschirila 2:281d8c268a8e 39 else
raduschirila 2:281d8c268a8e 40 first=false;
raduschirila 2:281d8c268a8e 41 if(y>0.6)//make the led blink to the heartbeat when signal reaches a certain high region, it will stay lit till the signal decreases below that value
raduschirila 2:281d8c268a8e 42 {
raduschirila 2:281d8c268a8e 43 led=1;
raduschirila 2:281d8c268a8e 44 }
raduschirila 2:281d8c268a8e 45 else
raduschirila 2:281d8c268a8e 46 {
raduschirila 2:281d8c268a8e 47 led=0;
raduschirila 2:281d8c268a8e 48 }
raduschirila 2:281d8c268a8e 49 //pc.printf("%.3f, %.3f\n",xi,y);
raduschirila 2:281d8c268a8e 50 ypast=y;sum+=y;no++;
raduschirila 0:850d65a7d593 51 }
raduschirila 0:850d65a7d593 52
raduschirila 0:850d65a7d593 53
raduschirila 0:850d65a7d593 54
raduschirila 0:850d65a7d593 55
raduschirila 0:850d65a7d593 56 #define LOW 0
raduschirila 0:850d65a7d593 57 #define HIGH 1
raduschirila 0:850d65a7d593 58
raduschirila 0:850d65a7d593 59 SPI max72_spi(PTD2, NC, PTD1);
raduschirila 0:850d65a7d593 60 DigitalOut load(PTD0); //will provide the load signal
raduschirila 0:850d65a7d593 61
raduschirila 0:850d65a7d593 62
raduschirila 0:850d65a7d593 63 char heart[8] = {0x00,0x36,0x7f,0x7f,0x3e,0x1c,0x08,0x00};
raduschirila 0:850d65a7d593 64
raduschirila 0:850d65a7d593 65
raduschirila 1:82127072abb8 66 //DISPLAY FUNCTIONS DO NOT TOUCH
raduschirila 1:82127072abb8 67
raduschirila 0:850d65a7d593 68 void write_to_max( int reg, int col)
raduschirila 0:850d65a7d593 69 {
raduschirila 0:850d65a7d593 70 load = LOW; // begin
raduschirila 0:850d65a7d593 71 max72_spi.write(reg); // specify register
raduschirila 0:850d65a7d593 72 max72_spi.write(col); // put data
raduschirila 0:850d65a7d593 73 load = HIGH; // make sure data is loaded (on rising edge of LOAD/CS)
raduschirila 0:850d65a7d593 74 }
raduschirila 0:850d65a7d593 75
raduschirila 0:850d65a7d593 76 //writes 8 bytes to the display
raduschirila 0:850d65a7d593 77 void pattern_to_display(char *testdata){
raduschirila 0:850d65a7d593 78 int cdata;
raduschirila 0:850d65a7d593 79 for(int idx = 0; idx <= 7; idx++) {
raduschirila 0:850d65a7d593 80 cdata = testdata[idx];
raduschirila 0:850d65a7d593 81 write_to_max(idx+1,cdata);
raduschirila 0:850d65a7d593 82 }
raduschirila 0:850d65a7d593 83 }
raduschirila 0:850d65a7d593 84
raduschirila 0:850d65a7d593 85
raduschirila 0:850d65a7d593 86 void setup_dot_matrix ()
raduschirila 0:850d65a7d593 87 {
raduschirila 0:850d65a7d593 88 // initiation of the max 7219
raduschirila 0:850d65a7d593 89 // SPI setup: 8 bits, mode 0
raduschirila 0:850d65a7d593 90 max72_spi.format(8, 0);
raduschirila 0:850d65a7d593 91
raduschirila 0:850d65a7d593 92
raduschirila 0:850d65a7d593 93
raduschirila 0:850d65a7d593 94 max72_spi.frequency(100000); //down to 100khx easier to scope ;-)
raduschirila 0:850d65a7d593 95
raduschirila 0:850d65a7d593 96
raduschirila 0:850d65a7d593 97 write_to_max(max7219_reg_scanLimit, 0x07);
raduschirila 0:850d65a7d593 98 write_to_max(max7219_reg_decodeMode, 0x00); // using an led matrix (not digits)
raduschirila 0:850d65a7d593 99 write_to_max(max7219_reg_shutdown, 0x01); // not in shutdown mode
raduschirila 0:850d65a7d593 100 write_to_max(max7219_reg_displayTest, 0x00); // no display test
raduschirila 0:850d65a7d593 101 for (int e=1; e<=8; e++) { // empty registers, turn all LEDs off
raduschirila 0:850d65a7d593 102 write_to_max(e,0);
raduschirila 0:850d65a7d593 103 }
raduschirila 0:850d65a7d593 104 // maxAll(max7219_reg_intensity, 0x0f & 0x0f); // the first 0x0f is the value you can set
raduschirila 0:850d65a7d593 105 write_to_max(max7219_reg_intensity, 0x08);
raduschirila 0:850d65a7d593 106
raduschirila 0:850d65a7d593 107 }
raduschirila 0:850d65a7d593 108
raduschirila 0:850d65a7d593 109 void clear(){
raduschirila 0:850d65a7d593 110 for (int e=1; e<=8; e++) { // empty registers, turn all LEDs off
raduschirila 0:850d65a7d593 111 write_to_max(e,0);
raduschirila 0:850d65a7d593 112 }
raduschirila 0:850d65a7d593 113 }
raduschirila 1:82127072abb8 114
raduschirila 1:82127072abb8 115 //END OF DISPLAY FUNCTIONS
raduschirila 1:82127072abb8 116
raduschirila 1:82127072abb8 117 void splash_screen()
raduschirila 0:850d65a7d593 118 {
raduschirila 0:850d65a7d593 119 setup_dot_matrix (); /* setup matric */
raduschirila 0:850d65a7d593 120 pattern_to_display(heart);
raduschirila 0:850d65a7d593 121 wait_ms(1000);
raduschirila 0:850d65a7d593 122 heart[7]=0x01;heart[0]=0x01;
raduschirila 0:850d65a7d593 123 for(int i=1;i<=8;++i)
raduschirila 0:850d65a7d593 124 {
raduschirila 0:850d65a7d593 125 pattern_to_display(heart);
raduschirila 0:850d65a7d593 126 wait(0.2);
raduschirila 0:850d65a7d593 127 heart[7]<<=1;
raduschirila 0:850d65a7d593 128 heart[7]|=1;
raduschirila 0:850d65a7d593 129 heart[0]=heart[7];
raduschirila 0:850d65a7d593 130 }
raduschirila 0:850d65a7d593 131 for(int i=1;i<=6;++i)
raduschirila 0:850d65a7d593 132 {
raduschirila 0:850d65a7d593 133 heart[i]=~heart[i];
raduschirila 0:850d65a7d593 134 }
raduschirila 0:850d65a7d593 135 pattern_to_display(heart);
raduschirila 0:850d65a7d593 136 wait(1.6);
raduschirila 0:850d65a7d593 137 clear();
raduschirila 0:850d65a7d593 138 }
raduschirila 1:82127072abb8 139
raduschirila 1:82127072abb8 140 int main()
raduschirila 1:82127072abb8 141 {
raduschirila 2:281d8c268a8e 142 pulse.attach(&get_pulse,0.0125);//attach the interrupt thing so it starts the ISR every 0.0125 s
raduschirila 2:281d8c268a8e 143 splash_screen();//wait for the pulse to be stable by showing stuff on the display so the user is happy knowing he is gay
raduschirila 1:82127072abb8 144 while(1)
raduschirila 1:82127072abb8 145 {
raduschirila 2:281d8c268a8e 146 o=(sum*100)/no-1;//attempt at doing the running average which at the moment does not work
raduschirila 1:82127072abb8 147 }
raduschirila 1:82127072abb8 148 }