system
5
1 //GSM Shield for Arduino
2 //www.open-electronics.org
3 //this code is based on the example of Arduino Labs
4
5 #include "<a title="SIM900" class="aal" target="_blank" rel="nofollow" href="http://store.open-electronics.org/Breakout/GSM%20Breakout">SIM900</a>.h"
6 #include "sms.h"
7 #include "SoftwareSerial.h"
8 #include "sms.h"
9 SMSGSM sms;
10 int red = 10; // RED LED connected to PWM pin 3
11 int green = 5; // GREEN LED connected to PWM pin 5
12 int blue = 6; // BLUE LED connected to PWM pin 6
13 int r=50; int g=100; int b=150;
14 int rup; int gup; int bup;
15
16 boolean started=false;
17 char smsbuffer[160];
18 char n[20];
19 int fader=1;
20 int inc=10;
21
22 void setup()
23 {
24 //Serial connection.
25 Serial.begin(9600);
26 Serial.println("GSM Shield testing.");
27 //Start configuration of shield with baudrate.
28 if (gsm.begin(2400)){
29 Serial.println("\nstatus=READY");
30 started=true;
31 }
32 else Serial.println("\nstatus=IDLE");
33 if(started){
34 delsms();
35 }
36
37 };
38
39 void loop()
40 {
41 int pos=0;
42 //Serial.println("Loop");
43 if(started){
44 pos=sms.IsSMSPresent(SMS_ALL);
45 if(pos){
46 Serial.println("IsSMSPresent at pos ");
47 Serial.println(pos);
48 sms.GetSMS(pos,n,smsbuffer,100);
49 Serial.println(n);
50 Serial.println(smsbuffer);
51 if(!strcmp(smsbuffer,"R")){
52 Serial.println("RED");
53 r=255;
54 g=0;
55 b=0;
56 }
57 if(!strcmp(smsbuffer,"G")){
58 Serial.println("GREEN");
59 r=0;
60 g=255;
61 b=0;
62 }
63 if(!strcmp(smsbuffer,"B")){
64 Serial.println("BLUE");
65 r=0;
66 g=0;
67 b=255;
68 }
69 if(!strcmp(smsbuffer,"P")){
70 Serial.println("PURPLE");
71 r=255;
72 g=0;
73 b=255;
74 }
75 if(!strcmp(smsbuffer,"Y")){
76 Serial.println("YELLOW");
77 r=255;
78 g=255;
79 b=0;
80 }
81 if(!strcmp(smsbuffer,"O")){
82 Serial.println("ORANGE");
83 r=255;
84 g=165;
85 b=0;
86 }
87 if(!strcmp(smsbuffer,"W")){
88 Serial.println("WHITE");
89 r=255;
90 g=255;
91 b=255;
92 }
93 if(!strcmp(smsbuffer,"F")){
94 Serial.println("FADER");
95 fader=1;
96 r=50; g=100; b=150;
97 }
98 else
99 {
100 fader=0;
101 }
102 rgb(r, g, b);
103 delsms();
104
105 }
106 if(fader){
107 funcfader();
108 }
109
110 }
111 };
112
113 void delsms(){
114 Serial.println("delsms");
115 for (int i=0; i<10; i++){ //do it max 10 times
116 int pos=sms.IsSMSPresent(SMS_ALL);
117 if (pos!=0){
118 Serial.print("\nFind SMS at the pos ");
119 Serial.println(pos);
120 if (sms.DeleteSMS(pos)==1){
121 Serial.print("\nDeleted SMS at the pos ");
122 Serial.println(pos);
123 }
124 else
125 {
126 Serial.print("\nCant del SMS at the pos ");
127 Serial.println(pos);
128 }
129 }
130 }
131
132 }
133
134 void funcfader(){
135 if (rup==1){r+=1;}
136 else{r-=1;}
137 if (r>=255){rup=0;}
138 if (r<=0){rup=1;}
139
140 if (gup==1){g+=1;}
141 else{g-=1;}
142 if (g>=255){gup=0;}
143 if (g<=0){gup=1;}
144
145 if (bup==1){b+=1;}
146 else{b-=1;}
147 if (b>=255){bup=0;}
148 if (b<=0){bup=1;}
149 rgb(r, g, b);
150 }
151
152 void rgb(int r, int g, int b)
153 {
1 if (r>255) r=255;
2 if (g>255) g=255;
3 if (b>255) b=255;
4 if (r<0) r=0;
5 if (g<0) g=0;
6 if (b<0) b=0;
7
8 analogWrite(red, r);
9 analogWrite(green, g);
10 analogWrite(blue, b);
11 }