Project For EEE212 Course

Dependencies:   mbed MAX7219

Committer:
yaman_yucel
Date:
Tue May 21 17:02:00 2019 +0000
Revision:
0:1a3e10a8f5d0
ProjeVol1;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
yaman_yucel 0:1a3e10a8f5d0 1
yaman_yucel 0:1a3e10a8f5d0 2 #include "mbed.h"
yaman_yucel 0:1a3e10a8f5d0 3 #include "max7219.h"
yaman_yucel 0:1a3e10a8f5d0 4 #define HIGHT 15
yaman_yucel 0:1a3e10a8f5d0 5 #define WIDTH 15
yaman_yucel 0:1a3e10a8f5d0 6 Max7219 device(PTD2, PTD3, PTD1, PTD0);
yaman_yucel 0:1a3e10a8f5d0 7 uint16_t DotArea[] = {
yaman_yucel 0:1a3e10a8f5d0 8 0b0101111111111111,
yaman_yucel 0:1a3e10a8f5d0 9 0b0100000000000001,
yaman_yucel 0:1a3e10a8f5d0 10 0b0101010101010101,
yaman_yucel 0:1a3e10a8f5d0 11 0b0100000000000001,
yaman_yucel 0:1a3e10a8f5d0 12 0b0101010101010101,
yaman_yucel 0:1a3e10a8f5d0 13 0b0100000000000001,
yaman_yucel 0:1a3e10a8f5d0 14 0b0101010101010101,
yaman_yucel 0:1a3e10a8f5d0 15 0b0100000000000001,
yaman_yucel 0:1a3e10a8f5d0 16
yaman_yucel 0:1a3e10a8f5d0 17 0b0101010101010101,
yaman_yucel 0:1a3e10a8f5d0 18 0b0100000000000001,
yaman_yucel 0:1a3e10a8f5d0 19 0b0101010101010101,
yaman_yucel 0:1a3e10a8f5d0 20 0b0100000000000001,
yaman_yucel 0:1a3e10a8f5d0 21 0b0101010101010101,
yaman_yucel 0:1a3e10a8f5d0 22 0b0100000000000001,
yaman_yucel 0:1a3e10a8f5d0 23 0b0111111111111101,
yaman_yucel 0:1a3e10a8f5d0 24 0b0000000000000000
yaman_yucel 0:1a3e10a8f5d0 25 };
yaman_yucel 0:1a3e10a8f5d0 26 const uint16_t DotAreaTemp[] = {
yaman_yucel 0:1a3e10a8f5d0 27 0b0101111111111111,
yaman_yucel 0:1a3e10a8f5d0 28 0b0100000000000001,
yaman_yucel 0:1a3e10a8f5d0 29 0b0101010101010101,
yaman_yucel 0:1a3e10a8f5d0 30 0b0100000000000001,
yaman_yucel 0:1a3e10a8f5d0 31 0b0101010101010101,
yaman_yucel 0:1a3e10a8f5d0 32 0b0100000000000001,
yaman_yucel 0:1a3e10a8f5d0 33 0b0101010101010101,
yaman_yucel 0:1a3e10a8f5d0 34 0b0100000000000001,
yaman_yucel 0:1a3e10a8f5d0 35
yaman_yucel 0:1a3e10a8f5d0 36 0b0101010101010101,
yaman_yucel 0:1a3e10a8f5d0 37 0b0100000000000001,
yaman_yucel 0:1a3e10a8f5d0 38 0b0101010101010101,
yaman_yucel 0:1a3e10a8f5d0 39 0b0100000000000001,
yaman_yucel 0:1a3e10a8f5d0 40 0b0101010101010101,
yaman_yucel 0:1a3e10a8f5d0 41 0b0100000000000001,
yaman_yucel 0:1a3e10a8f5d0 42 0b0111111111111101,
yaman_yucel 0:1a3e10a8f5d0 43 0b0000000000000000
yaman_yucel 0:1a3e10a8f5d0 44 };
yaman_yucel 0:1a3e10a8f5d0 45 AnalogIn ain(A0);
yaman_yucel 0:1a3e10a8f5d0 46 void sendArray();
yaman_yucel 0:1a3e10a8f5d0 47
yaman_yucel 0:1a3e10a8f5d0 48 int main(){
yaman_yucel 0:1a3e10a8f5d0 49 const int device_number = 4;
yaman_yucel 0:1a3e10a8f5d0 50
yaman_yucel 0:1a3e10a8f5d0 51 device.set_num_devices(device_number);
yaman_yucel 0:1a3e10a8f5d0 52
yaman_yucel 0:1a3e10a8f5d0 53 max7219_configuration_t cfg = {
yaman_yucel 0:1a3e10a8f5d0 54 .device_number = device_number,
yaman_yucel 0:1a3e10a8f5d0 55 .decode_mode = 0,
yaman_yucel 0:1a3e10a8f5d0 56 .intensity = Max7219::MAX7219_INTENSITY_5,
yaman_yucel 0:1a3e10a8f5d0 57 .scan_limit = Max7219::MAX7219_SCAN_8
yaman_yucel 0:1a3e10a8f5d0 58 };
yaman_yucel 0:1a3e10a8f5d0 59
yaman_yucel 0:1a3e10a8f5d0 60 device.init_display(cfg);
yaman_yucel 0:1a3e10a8f5d0 61 device.enable_display();
yaman_yucel 0:1a3e10a8f5d0 62 device.set_display_test();
yaman_yucel 0:1a3e10a8f5d0 63 wait(1);
yaman_yucel 0:1a3e10a8f5d0 64 device.clear_display_test();
yaman_yucel 0:1a3e10a8f5d0 65
yaman_yucel 0:1a3e10a8f5d0 66
yaman_yucel 0:1a3e10a8f5d0 67
yaman_yucel 0:1a3e10a8f5d0 68 while(1){
yaman_yucel 0:1a3e10a8f5d0 69 sendArray();
yaman_yucel 0:1a3e10a8f5d0 70 wait(4);
yaman_yucel 0:1a3e10a8f5d0 71 uint8_t i, j, val, mod;
yaman_yucel 0:1a3e10a8f5d0 72 int8_t x, y;
yaman_yucel 0:1a3e10a8f5d0 73
yaman_yucel 0:1a3e10a8f5d0 74 // Maze Make
yaman_yucel 0:1a3e10a8f5d0 75 mod = 4;
yaman_yucel 0:1a3e10a8f5d0 76 for (i = 2; i < HIGHT - 2; i += 2) {
yaman_yucel 0:1a3e10a8f5d0 77 for (j = 3; j < WIDTH - 1; j += 2) {
yaman_yucel 0:1a3e10a8f5d0 78 DotArea[i] |= (0x8000 >> j);
yaman_yucel 0:1a3e10a8f5d0 79 do{
yaman_yucel 0:1a3e10a8f5d0 80 //Roll a stick
yaman_yucel 0:1a3e10a8f5d0 81 val = (uint8_t)(ain.read_u16() & 0x00FF) % mod;
yaman_yucel 0:1a3e10a8f5d0 82 x = 0, y = 0;
yaman_yucel 0:1a3e10a8f5d0 83 if (val == 0)y = 1;
yaman_yucel 0:1a3e10a8f5d0 84 if (val == 1)x = -1;
yaman_yucel 0:1a3e10a8f5d0 85 if (val == 2)x = 1;
yaman_yucel 0:1a3e10a8f5d0 86 if (val == 3)y = -1;
yaman_yucel 0:1a3e10a8f5d0 87 }while ((DotArea[i + y] & (0x8000 >> (j + x))));
yaman_yucel 0:1a3e10a8f5d0 88 DotArea[i + y] |= (0x8000 >> (j + x));
yaman_yucel 0:1a3e10a8f5d0 89 }
yaman_yucel 0:1a3e10a8f5d0 90 mod = 3;
yaman_yucel 0:1a3e10a8f5d0 91 }
yaman_yucel 0:1a3e10a8f5d0 92 sendArray();
yaman_yucel 0:1a3e10a8f5d0 93 wait(10);
yaman_yucel 0:1a3e10a8f5d0 94
yaman_yucel 0:1a3e10a8f5d0 95 for(int i = 0; i < 16;i++)
yaman_yucel 0:1a3e10a8f5d0 96 {
yaman_yucel 0:1a3e10a8f5d0 97 DotArea[i] = DotAreaTemp[i];
yaman_yucel 0:1a3e10a8f5d0 98 }
yaman_yucel 0:1a3e10a8f5d0 99 }
yaman_yucel 0:1a3e10a8f5d0 100 }
yaman_yucel 0:1a3e10a8f5d0 101
yaman_yucel 0:1a3e10a8f5d0 102 void sendArray()
yaman_yucel 0:1a3e10a8f5d0 103 {
yaman_yucel 0:1a3e10a8f5d0 104 for(int i = 0; i < 8;i++)
yaman_yucel 0:1a3e10a8f5d0 105 {
yaman_yucel 0:1a3e10a8f5d0 106 device.write_digit(1,i+1, (uint8_t)(DotArea[i] / 256));
yaman_yucel 0:1a3e10a8f5d0 107 }
yaman_yucel 0:1a3e10a8f5d0 108
yaman_yucel 0:1a3e10a8f5d0 109 for(int i = 0; i < 8;i++)
yaman_yucel 0:1a3e10a8f5d0 110 {
yaman_yucel 0:1a3e10a8f5d0 111 device.write_digit(2,i+1, (uint8_t)(DotArea[i+8] / 256));
yaman_yucel 0:1a3e10a8f5d0 112 }
yaman_yucel 0:1a3e10a8f5d0 113
yaman_yucel 0:1a3e10a8f5d0 114 for(int i = 0; i < 8;i++)
yaman_yucel 0:1a3e10a8f5d0 115 {
yaman_yucel 0:1a3e10a8f5d0 116 device.write_digit(3,i+1, (uint8_t) (DotArea[i]));
yaman_yucel 0:1a3e10a8f5d0 117 }
yaman_yucel 0:1a3e10a8f5d0 118 for(int i = 0; i < 8;i++)
yaman_yucel 0:1a3e10a8f5d0 119 {
yaman_yucel 0:1a3e10a8f5d0 120 device.write_digit(4,i+1, (uint8_t) (DotArea[i+8]));
yaman_yucel 0:1a3e10a8f5d0 121 }
yaman_yucel 0:1a3e10a8f5d0 122 }
yaman_yucel 0:1a3e10a8f5d0 123
yaman_yucel 0:1a3e10a8f5d0 124