school project

Dependencies:   MMA8451Q mbed

Committer:
xlizne01
Date:
Mon Jan 11 22:34:33 2016 +0000
Revision:
1:b23831b703fe
Parent:
0:ae588eb31707
Child:
2:3278e4fd8fc2
2

Who changed what in which revision?

UserRevisionLine numberNew contents of line
xlizne01 0:ae588eb31707 1 #include "mbed.h"
xlizne01 1:b23831b703fe 2 #include "MMA8451Q.h"
xlizne01 1:b23831b703fe 3
xlizne01 1:b23831b703fe 4 #define MMA8451_I2C_ADDRESS (0x1d<<1)
xlizne01 1:b23831b703fe 5
xlizne01 0:ae588eb31707 6 DigitalOut prvni(PTE5);
xlizne01 0:ae588eb31707 7 DigitalOut druhy(PTE4);
xlizne01 0:ae588eb31707 8 DigitalOut treti(PTE3);
xlizne01 0:ae588eb31707 9 DigitalOut ctvrty(PTE2);
xlizne01 0:ae588eb31707 10 DigitalOut paty(PTB11);
xlizne01 0:ae588eb31707 11 DigitalOut sesty(PTB10);
xlizne01 0:ae588eb31707 12 DigitalOut sedmy(PTB9);
xlizne01 0:ae588eb31707 13 DigitalOut osmy(PTB8);
xlizne01 0:ae588eb31707 14
xlizne01 0:ae588eb31707 15 DigitalOut Rled1(PTC9);
xlizne01 0:ae588eb31707 16 DigitalOut Rled2(PTC8);
xlizne01 0:ae588eb31707 17 DigitalOut Rled3(PTA5);
xlizne01 0:ae588eb31707 18 DigitalOut Rled4(PTA4);
xlizne01 0:ae588eb31707 19 DigitalOut Rled5(PTA12);
xlizne01 0:ae588eb31707 20 DigitalOut Rled6(PTD4);
xlizne01 0:ae588eb31707 21 DigitalOut Rled7(PTA1);
xlizne01 0:ae588eb31707 22 DigitalOut Rled8(PTA2);
xlizne01 0:ae588eb31707 23
xlizne01 0:ae588eb31707 24 DigitalOut Gled1(PTA13);
xlizne01 0:ae588eb31707 25 DigitalOut Gled2(PTD5);
xlizne01 0:ae588eb31707 26 DigitalOut Gled3(PTD0);
xlizne01 0:ae588eb31707 27 DigitalOut Gled4(PTD2);
xlizne01 0:ae588eb31707 28 DigitalOut Gled5(PTD3);
xlizne01 0:ae588eb31707 29 DigitalOut Gled6(PTD1);
xlizne01 0:ae588eb31707 30 DigitalOut Gled7(PTE31);
xlizne01 0:ae588eb31707 31 DigitalOut Gled8(PTB0);
xlizne01 0:ae588eb31707 32
xlizne01 0:ae588eb31707 33 DigitalOut Bled1(PTC1);
xlizne01 0:ae588eb31707 34 DigitalOut Bled2(PTE29);
xlizne01 0:ae588eb31707 35 DigitalOut Bled3(PTC2);
xlizne01 0:ae588eb31707 36 DigitalOut Bled4(PTB3);
xlizne01 0:ae588eb31707 37 DigitalOut Bled5(PTB2);
xlizne01 0:ae588eb31707 38 DigitalOut Bled6(PTE21);
xlizne01 0:ae588eb31707 39 DigitalOut Bled7(PTE20);
xlizne01 0:ae588eb31707 40 DigitalOut Bled8(PTB1);
xlizne01 0:ae588eb31707 41
xlizne01 0:ae588eb31707 42
xlizne01 0:ae588eb31707 43 int i,j,k;
xlizne01 0:ae588eb31707 44 int RED, GREEN, BLUE;
xlizne01 0:ae588eb31707 45 int RledA, RledB, GledA, GledB, BledA, BledB;
xlizne01 0:ae588eb31707 46
xlizne01 0:ae588eb31707 47 int main()
xlizne01 0:ae588eb31707 48 {
xlizne01 1:b23831b703fe 49 MMA8451Q acc(PTE25, PTE24, MMA8451_I2C_ADDRESS);
xlizne01 0:ae588eb31707 50
xlizne01 0:ae588eb31707 51 while(1)
xlizne01 0:ae588eb31707 52 {
xlizne01 0:ae588eb31707 53
xlizne01 0:ae588eb31707 54 for(k=1;k<5;k++)
xlizne01 0:ae588eb31707 55 {
xlizne01 0:ae588eb31707 56
xlizne01 0:ae588eb31707 57 if(k==1)
xlizne01 0:ae588eb31707 58 {
xlizne01 0:ae588eb31707 59 prvni=1;
xlizne01 0:ae588eb31707 60 druhy=1;
xlizne01 0:ae588eb31707 61 treti=0;
xlizne01 0:ae588eb31707 62 ctvrty=0;
xlizne01 0:ae588eb31707 63 paty=0;
xlizne01 0:ae588eb31707 64 sesty=0;
xlizne01 0:ae588eb31707 65 sedmy=0;
xlizne01 0:ae588eb31707 66 osmy=0;
xlizne01 0:ae588eb31707 67 }
xlizne01 0:ae588eb31707 68
xlizne01 0:ae588eb31707 69 if(k==2)
xlizne01 0:ae588eb31707 70 {
xlizne01 0:ae588eb31707 71 prvni=0;
xlizne01 0:ae588eb31707 72 druhy=0;
xlizne01 0:ae588eb31707 73 treti=1;
xlizne01 0:ae588eb31707 74 ctvrty=1;
xlizne01 0:ae588eb31707 75 paty=0;
xlizne01 0:ae588eb31707 76 sesty=0;
xlizne01 0:ae588eb31707 77 sedmy=0;
xlizne01 0:ae588eb31707 78 osmy=0;
xlizne01 0:ae588eb31707 79 }
xlizne01 0:ae588eb31707 80
xlizne01 0:ae588eb31707 81 if(k==3)
xlizne01 0:ae588eb31707 82 {
xlizne01 0:ae588eb31707 83 prvni=0;
xlizne01 0:ae588eb31707 84 druhy=0;
xlizne01 0:ae588eb31707 85 treti=0;
xlizne01 0:ae588eb31707 86 ctvrty=0;
xlizne01 0:ae588eb31707 87 paty=1;
xlizne01 0:ae588eb31707 88 sesty=1;
xlizne01 0:ae588eb31707 89 sedmy=0;
xlizne01 0:ae588eb31707 90 osmy=0;
xlizne01 0:ae588eb31707 91 }
xlizne01 0:ae588eb31707 92
xlizne01 0:ae588eb31707 93 if(k==4)
xlizne01 0:ae588eb31707 94 {
xlizne01 0:ae588eb31707 95 prvni=0;
xlizne01 0:ae588eb31707 96 druhy=0;
xlizne01 0:ae588eb31707 97 treti=0;
xlizne01 0:ae588eb31707 98 ctvrty=0;
xlizne01 0:ae588eb31707 99 paty=0;
xlizne01 0:ae588eb31707 100 sesty=0;
xlizne01 0:ae588eb31707 101 sedmy=1;
xlizne01 0:ae588eb31707 102 osmy=1;
xlizne01 0:ae588eb31707 103 }
xlizne01 0:ae588eb31707 104
xlizne01 0:ae588eb31707 105 for(j=1;j<5;j++)
xlizne01 0:ae588eb31707 106 {
xlizne01 0:ae588eb31707 107
xlizne01 0:ae588eb31707 108 if(j==1)
xlizne01 0:ae588eb31707 109 {
xlizne01 1:b23831b703fe 110 RED=abs(acc.getAccX())*5;
xlizne01 1:b23831b703fe 111 BLUE=abs(acc.getAccY())*5;
xlizne01 1:b23831b703fe 112 GREEN=abs(acc.getAccZ())*5;
xlizne01 0:ae588eb31707 113 }
xlizne01 0:ae588eb31707 114
xlizne01 0:ae588eb31707 115 if(j==2)
xlizne01 0:ae588eb31707 116 {
xlizne01 1:b23831b703fe 117 RED=abs(acc.getAccX())*5;
xlizne01 1:b23831b703fe 118 BLUE=abs(acc.getAccY())*5;
xlizne01 1:b23831b703fe 119 GREEN=abs(acc.getAccZ())*2;
xlizne01 0:ae588eb31707 120 }
xlizne01 0:ae588eb31707 121
xlizne01 0:ae588eb31707 122 if(j==3)
xlizne01 0:ae588eb31707 123 {
xlizne01 1:b23831b703fe 124 RED=abs(acc.getAccX())*5;
xlizne01 1:b23831b703fe 125 BLUE=abs(acc.getAccY())*5;
xlizne01 1:b23831b703fe 126 GREEN=abs(acc.getAccZ())*2
xlizne01 0:ae588eb31707 127 }
xlizne01 0:ae588eb31707 128
xlizne01 0:ae588eb31707 129 if(j==4)
xlizne01 0:ae588eb31707 130 {
xlizne01 1:b23831b703fe 131 RED=abs(acc.getAccX())*5;
xlizne01 1:b23831b703fe 132 BLUE=abs(acc.getAccY())*5;
xlizne01 1:b23831b703fe 133 GREEN=abs(acc.getAccZ())*2;
xlizne01 0:ae588eb31707 134 }
xlizne01 0:ae588eb31707 135
xlizne01 0:ae588eb31707 136 for(i=11;i>0;i--)
xlizne01 0:ae588eb31707 137 {
xlizne01 0:ae588eb31707 138
xlizne01 0:ae588eb31707 139 if(RED>0)
xlizne01 0:ae588eb31707 140 {
xlizne01 0:ae588eb31707 141 RledA=1;
xlizne01 0:ae588eb31707 142 RledB=1;
xlizne01 0:ae588eb31707 143 }
xlizne01 0:ae588eb31707 144 else
xlizne01 0:ae588eb31707 145 {
xlizne01 0:ae588eb31707 146 RledA=0;
xlizne01 0:ae588eb31707 147 RledB=0;
xlizne01 0:ae588eb31707 148 }
xlizne01 0:ae588eb31707 149
xlizne01 0:ae588eb31707 150 if(GREEN>0)
xlizne01 0:ae588eb31707 151 {
xlizne01 0:ae588eb31707 152 GledA=1;
xlizne01 0:ae588eb31707 153 GledB=1;
xlizne01 0:ae588eb31707 154 }
xlizne01 0:ae588eb31707 155 else
xlizne01 0:ae588eb31707 156 {
xlizne01 0:ae588eb31707 157 GledA=0;
xlizne01 0:ae588eb31707 158 GledB=0;
xlizne01 0:ae588eb31707 159 }
xlizne01 0:ae588eb31707 160
xlizne01 0:ae588eb31707 161 if(BLUE>0)
xlizne01 0:ae588eb31707 162 {
xlizne01 0:ae588eb31707 163 BledA=1;
xlizne01 0:ae588eb31707 164 BledB=1;
xlizne01 0:ae588eb31707 165 }
xlizne01 0:ae588eb31707 166 else
xlizne01 0:ae588eb31707 167 {
xlizne01 0:ae588eb31707 168 BledA=0;
xlizne01 0:ae588eb31707 169 BledB=0;
xlizne01 0:ae588eb31707 170 }
xlizne01 0:ae588eb31707 171
xlizne01 0:ae588eb31707 172 if(j==1)
xlizne01 0:ae588eb31707 173 {
xlizne01 0:ae588eb31707 174 Rled1=RledA;
xlizne01 0:ae588eb31707 175 Rled2=RledB;
xlizne01 0:ae588eb31707 176 Gled1=GledA;
xlizne01 0:ae588eb31707 177 Gled2=GledB;
xlizne01 0:ae588eb31707 178 Bled1=BledA;
xlizne01 0:ae588eb31707 179 Bled2=BledB;
xlizne01 0:ae588eb31707 180 }
xlizne01 0:ae588eb31707 181
xlizne01 0:ae588eb31707 182 if(j==2)
xlizne01 0:ae588eb31707 183 {
xlizne01 0:ae588eb31707 184 Rled3=RledA;
xlizne01 0:ae588eb31707 185 Rled4=RledB;
xlizne01 0:ae588eb31707 186 Gled3=GledA;
xlizne01 0:ae588eb31707 187 Gled4=GledB;
xlizne01 0:ae588eb31707 188 Bled3=BledA;
xlizne01 0:ae588eb31707 189 Bled4=BledB;
xlizne01 0:ae588eb31707 190 }
xlizne01 0:ae588eb31707 191
xlizne01 0:ae588eb31707 192 if(j==3)
xlizne01 0:ae588eb31707 193 {
xlizne01 0:ae588eb31707 194 Rled5=RledA;
xlizne01 0:ae588eb31707 195 Rled6=RledB;
xlizne01 0:ae588eb31707 196 Gled5=GledA;
xlizne01 0:ae588eb31707 197 Gled6=GledB;
xlizne01 0:ae588eb31707 198 Bled5=BledA;
xlizne01 0:ae588eb31707 199 Bled6=BledB;
xlizne01 0:ae588eb31707 200 }
xlizne01 0:ae588eb31707 201
xlizne01 0:ae588eb31707 202 if(j==4)
xlizne01 0:ae588eb31707 203 {
xlizne01 0:ae588eb31707 204 Rled7=RledA;
xlizne01 0:ae588eb31707 205 Rled8=RledB;
xlizne01 0:ae588eb31707 206 Gled7=GledA;
xlizne01 0:ae588eb31707 207 Gled8=GledB;
xlizne01 0:ae588eb31707 208 Bled7=BledA;
xlizne01 0:ae588eb31707 209 Bled8=BledB;
xlizne01 0:ae588eb31707 210 }
xlizne01 0:ae588eb31707 211
xlizne01 0:ae588eb31707 212 wait(0.00005);
xlizne01 0:ae588eb31707 213 RED--;
xlizne01 0:ae588eb31707 214 BLUE--;
xlizne01 0:ae588eb31707 215 GREEN--;
xlizne01 0:ae588eb31707 216
xlizne01 0:ae588eb31707 217 }
xlizne01 0:ae588eb31707 218 }
xlizne01 0:ae588eb31707 219 }
xlizne01 0:ae588eb31707 220 }
xlizne01 0:ae588eb31707 221 }
xlizne01 0:ae588eb31707 222
xlizne01 0:ae588eb31707 223
xlizne01 0:ae588eb31707 224