Components and supplies
Arduino Mega 2560
Project description
Code
SLAVE
arduino
The Slave is controlling all umbrellas.
1/*LAST CHANGES 2017-10-26 2 _20171026_SLAVE_SLAVE_DurationOpening 3 */ 4/*THIS IS THE SLAVE! 5 This programm plays each single umbrellas it receives from the Master 6/* 7//PAU = PinAssignmentUmbrella 8//----------------------------------------------------------------------// 9//----------------------------------------------------------------------// 10//----------------------------------------------------------------------// 11int WaitForSglUmbrella = 2000; 12/*START defining global Master-Slave Outputs*/ 13int DO_PAU[6] = {14, 15, 16, 17, 18, 19}; //ARDUINO PINs: Digital outputs for PAU communication 14int Takt = 1; //ARDUINO PIN 1: Takt manages whether SLAVE listens (if HIGH, Slave listens) 15int Data = 20; //ARDUINO PIN 20: Data indicates whether umbrella should be closed (LOW) or opened (HIGH) 16int Busy = 21; //ARDUINO PIN 21: Busy indicates whether Slave is Busy with reading PAUS (HIGH) or finished (LOW) 17/*END defining globalMaster-Slave Outputs*/ 18/*START defining Umbrelal ARDUINO Pins*/ 19int UmbrellaPin[35] = {2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 44, 46, 48, 50, 52, 23, 25, 27, 29, 31, 33, 35}; //ARDUINO PINs: Digital Outputs 20/*END defining Umbrelal ARDUINO Pins*/ 21boolean JERKPROGRAMM = false; //Special programm if all 22int SumOfAllPAUs = 0; //Sum of all PAUs >> Indicates which umbrella it is about 23int WhichUmbrella[35] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; 24/*START INT FOR JERK PROGRAMM*/ 25int JerkWasRunning = 0; 26long DelayTillNextJerk; //Delay till next umbrella jerks 27int DelayTillNextJerkCounter = 0; 28int DelayTillNextJerkMIN = 10000; //min FPS till next umbrella jerks 29int DelayTillNextJerkMAX = 500000; //max FPS till next umbrella jerks 30long JerkUmbrella; //Will store the PIN of the JerkUmbrella 31int DurationJerkUmbrella = 200; //Duration of which jerking umbrella closes 32int CountingWhileJerking = 0; //Counter till Umbrella stops jerking 33/*END INT FOR JERK PROGRAMM*/ 34boolean newStart = true; 35//----------------------------------------------------------------------// 36//----------------------------------------------------------------------// 37//----------------------------------------------------------------------// 38void setup() { 39 //Serial.begin(9600); 40 Serial.end(); 41 Serial1.end(); 42 Serial2.end(); 43 Serial3.end(); 44 45 //randomSeed(analogRead(0));//for my Random numbers; 46 //START Defining all communication pins// 47 for (int x = 0; x < 6; x++) { //Declaring all 6 DO-PAUs as Digital Inputs 48 pinMode(DO_PAU[x], INPUT); 49 } 50 pinMode(Takt, INPUT); 51 pinMode(Data, INPUT); 52 pinMode(Busy, OUTPUT); digitalWrite(Busy, LOW); 53 //END Defining all communication pins// 54 //START Defining all ARDUINO sensor pins// 55 for (int x = 0; x < 35; x++) { //Declaring all Umbrella Pins as Digital Output 56 pinMode(UmbrellaPin[x], OUTPUT); digitalWrite(UmbrellaPin[x], LOW); 57 } 58 //END Defining all ARDUINO sensor pins// 59} 60//----------------------------------------------------------------------// 61//----------------------------------------------------------------------// 62//----------------------------------------------------------------------// 63void loop() { 64 if (newStart == true){ 65 newStart = false; 66 delay(4000); 67 } 68 //START Receive Data from Master + set single Umbrella 69 if(digitalRead(Takt) == 1){ //Data is ready to be processed 70 digitalWrite(Busy, 1); //Now SLAVE is busy reading data 71 SumOfAllPAUs = -1;//Umbrella Array starts with 0! 72 if(digitalRead(DO_PAU[0]) == HIGH){SumOfAllPAUs = SumOfAllPAUs+1;} 73 if(digitalRead(DO_PAU[1]) == HIGH){SumOfAllPAUs = SumOfAllPAUs+2;} 74 if(digitalRead(DO_PAU[2]) == HIGH){SumOfAllPAUs = SumOfAllPAUs+4;} 75 if(digitalRead(DO_PAU[3]) == HIGH){SumOfAllPAUs = SumOfAllPAUs+8;} 76 if(digitalRead(DO_PAU[4]) == HIGH){SumOfAllPAUs = SumOfAllPAUs+16;} 77 if(digitalRead(DO_PAU[5]) == HIGH){SumOfAllPAUs = SumOfAllPAUs+32;} 78 //START Set Umbrella/JERK Data 79 80 if(digitalRead(Data) == 1){WhichUmbrella[SumOfAllPAUs] = 1;} 81 else{WhichUmbrella[SumOfAllPAUs] = 0;} 82 //END Set Umbrella/JERK Data 83 84 //END Receive Data from Master 85 86 //START Setting Single Umbrella 87 88 89 digitalWrite(UmbrellaPin[SumOfAllPAUs], (WhichUmbrella[SumOfAllPAUs]));//Open or Closes Umbrella 90 91 digitalWrite(Busy, 0); //Now SLAVE is finished with reading and setting data 92//END Setting Single Umbrella 93} 94 95} 96 97 98 99
MASTER
arduino
The Master is checking all PIR sensors
1/*LAST CHANGES 2017-10-26 2 * /*THIS IS THE MASTER! 3 This programm is setting the communication pins (Master > Slave) 4 for each of the 35 umbrellas*/ 5//PAU = PinAssignmentUmbrella 6//----------------------------------------------------------------------// 7//----------------------------------------------------------------------// 8//----------------------------------------------------------------------// 9/*START defining global Master-Slave Outputs*/ 10int DO_PAU[6] = {14, 15, 16, 17, 18, 19}; //ARDUINO PINs: Digital outputs for PAU communication 11int Takt = 1; //ARDUINO PIN 1: Takt manages whether SLAVE listens (if HIGH, Slave listens) 12int Data = 20; //ARDUINO PIN 20: Data indicates whether umbrella should be closed (LOW) or opened (HIGH) 13int Busy = 21; //ARDUINO PIN 21: Busy indicates whether Slave is Busy with reading PAUS (HIGH) or finished (LOW) 14/*END defining globalMaster-Slave Outputs*/ 15//----------------------------------------------------------------------// 16/*START UmbrellaSetPins INT*/ 17int PAU[] = {//Pin assignment for each umbrella 18 1, 0, 0, 0, 0, 0, //1 19 0, 1, 0, 0, 0, 0, //2 20 1, 1, 0, 0, 0, 0, //3 21 0, 0, 1, 0, 0, 0, //4 22 1, 0, 1, 0, 0, 0, //5 23 0, 1, 1, 0, 0, 0, //6 24 1, 1, 1, 0, 0, 0, //7 25 0, 0, 0, 1, 0, 0, //8 26 1, 0, 0, 1, 0, 0, //9 27 0, 1, 0, 1, 0, 0, //10 28 1, 1, 0, 1, 0, 0, //11 29 0, 0, 1, 1, 0, 0, //12 30 1, 0, 1, 1, 0, 0, //13 31 0, 1, 1, 1, 0, 0, //14 32 1, 1, 1, 1, 0, 0, //15 33 0, 0, 0, 0, 1, 0, //16 34 1, 0, 0, 0, 1, 0, //17 35 0, 1, 0, 0, 1, 0, //18 36 1, 1, 0, 0, 1, 0, //19 37 0, 0, 1, 0, 1, 0, //20 38 1, 0, 1, 0, 1, 0, //21 39 0, 1, 1, 0, 1, 0, //22 40 1, 1, 1, 0, 1, 0, //23 41 0, 0, 0, 1, 1, 0, //24 42 1, 0, 0, 1, 1, 0, //25 43 0, 1, 0, 1, 1, 0, //26 44 1, 1, 0, 1, 1, 0, //27 45 0, 0, 1, 1, 1, 0, //28 46 1, 0, 1, 1, 1, 0, //29 47 0, 1, 1, 1, 1, 0, //30 48 1, 1, 1, 1, 1, 0, //31 49 0, 0, 0, 0, 0, 1, //32 50 1, 0, 0, 0, 0, 1, //33 51 0, 1, 0, 0, 0, 1, //34 52 1, 1, 0, 0, 0, 1 //35 53}; 54int NumberEffect[20] = {1, 2, 2, 2, 1, 2, 2, 2, 1, 2, 2, 2, 1, 2, 2, 2, 1, 2, 2, 2}; //How many umbrellas does the sensor effect? 55int EffectedUmbrella[40] = {0,10,1,11,2,12,3,13,4,14,5,15,6,16,7,17,8,18,9,19,0,20,30,21,0,22,31,23,0,24,32,25,0,26,33,27,0,28,34,29}; 56/*END UmbrellaSetPins INT*/ 57//----------------------------------------------------------------------// 58/*To be adapted: FPS for SensorChecking*/ 59int DurationSensorChecking = 5000; //Duration in FPS for Trigger > Echo 60//int DurationSensorChecking = 30000; //Duration in FPS for Trigger > Echo 61int SecurityDelaySensor = 50; //Wait between two sensors for safety reasons to avoid interference. 62//----------------------------------------------------------------------// 63/*START ints for all Sensor-Changes*/ 64int SensorChange[20] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; //Indicates whether a sensor changes its Data and therefore needs umbrella action 65int CurrentSensorData[20] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; //Managed by the actual sensors > Sth Detected = 1 / Nothing detected = 0 66int PreviousSensorData[20] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; //Saved data from previous checking 67/*END ints for all Sensor-Changes*/ 68//----------------------------------------------------------------------// 69/*START defining Sensor ARDUINO Pins*/ 70int SensorTrigger[20] = {3, 5, 7, 9, 11, 13, 24, 28, 32, 36, 40, 44, 48, 52, 25, 29, 33, 37, 41, 45}; //ARDUINO PINs: Digital Outputs 71int SensorEcho[20] = {2, 4, 6, 8, 10, 12, 22, 26, 30, 34, 38, 42, 46, 50, 23, 27, 31, 35, 39, 43}; //ARDUINO PINs: Digital Inputs 72/*END defining Sensor ARDUINO Pins*/ 73int WhichSensor = 0; 74int AllSensorsNull = 0; 75boolean newStart = true; 76/*DelayCounter so that Umbrella stays open some time*/ 77int DelayCounterUmbrella[20] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; //Stores delay for each umbrella 78int DelayCounter = 5000; //Delay tbd. 79int secondUmbrellaDelay = 300; //Delay until 2nd Umbrella reacts. 80//----------------------------------------------------------------------// 81//----------------------------------------------------------------------// 82//----------------------------------------------------------------------// 83void setup() { 84 //Serial.begin(9600); 85 Serial.end(); 86 Serial1.end(); 87 Serial2.end(); 88 Serial3.end(); 89 //START Defining all communication pins// 90 for (int x = 0; x < 6; x++) { //Declaring all 6 DO-PAUs as Digital Outputs 91 pinMode(DO_PAU[x], OUTPUT); 92 digitalWrite(DO_PAU[x], LOW);//Setting all 6 DO-PAUs to LOW 93 } 94 pinMode(Takt, OUTPUT); digitalWrite(Takt, LOW); 95 pinMode(Data, OUTPUT); digitalWrite(Data, LOW); 96 pinMode(Busy, INPUT); 97 //END Defining all communication pins// 98 //START Defining all ARDUINO sensor pins// 99 for (int x = 0; x < 20; x++) { //Declaring all Trigger Pins as Digital Output, Echo as Digital Input 100 pinMode(SensorTrigger[x], OUTPUT); digitalWrite(SensorTrigger[x], LOW); 101 pinMode(SensorEcho[x], INPUT); 102 } 103 //END Defining all ARDUINO sensor pins// 104} 105//----------------------------------------------------------------------// 106//----------------------------------------------------------------------// 107//----------------------------------------------------------------------// 108void loop() { 109 if (newStart == true){ 110 newStart = false; 111 delay(1000); 112 } 113 //START Checking Sensor [WhichSensor] for x FPS 114 if(digitalRead(SensorEcho[WhichSensor]) == HIGH){CurrentSensorData[WhichSensor] = 1; 115 DelayCounterUmbrella[WhichSensor] = 0;} 116 else { 117 if(DelayCounterUmbrella[WhichSensor] == DelayCounter){ 118 CurrentSensorData[WhichSensor] = 0; 119 } 120 else{DelayCounterUmbrella[WhichSensor]++;} 121 } 122 //END Checking Sensor [WhichSensor] for x FPS 123 //START Checking if something changed regarding the current sensor 124 if (CurrentSensorData[WhichSensor] == PreviousSensorData[WhichSensor]) { 125 SensorChange[WhichSensor] = 0; 126 } 127 else { 128 SensorChange[WhichSensor] = 1; 129 } 130 131 //END Checking if something changed regarding the current sensor 132 //START communicating Change to SLAVE 133 if (SensorChange[WhichSensor] == 1) { // if change = true, start communication 134 while (digitalRead(Busy) == HIGH) { 135 delay(1); // >>while SLAVE busy, don't continue. 136 } 137 //START Setting PAU for current Umbrella (NrUmbrella)// 138 digitalWrite(DO_PAU[0], (PAU[(((EffectedUmbrella[WhichSensor])* 6) + 0)]) ); 139 digitalWrite(DO_PAU[1], (PAU[(((EffectedUmbrella[WhichSensor])* 6) + 1)]) ); 140 digitalWrite(DO_PAU[2], (PAU[(((EffectedUmbrella[WhichSensor])* 6) + 2)]) ); 141 digitalWrite(DO_PAU[3], (PAU[(((EffectedUmbrella[WhichSensor])* 6) + 3)]) ); 142 digitalWrite(DO_PAU[4], (PAU[(((EffectedUmbrella[WhichSensor])* 6) + 4)]) ); 143 digitalWrite(DO_PAU[5], (PAU[(((EffectedUmbrella[WhichSensor])* 6) + 5)]) ); 144 //END Setting PAU per Umbrella// 145 if (CurrentSensorData[WhichSensor] == 1) { 146 digitalWrite((Data), 1); //Set Data for Slave. 147 } else { 148 digitalWrite((Data), 0); 149 } 150 PreviousSensorData[WhichSensor] = CurrentSensorData[WhichSensor]; //"Previous state" is now the current one 151 SensorChange[WhichSensor] = 0; //There's no current change on this sensor 152 digitalWrite((Takt), 1); //Now the date is ready to be read by SLAVE 153 //AS SOON AS SLAVE STARTS READING DATA (>> BUSY > HIGH), TAKT > 0. WAIT FOR IT. 154 while (digitalRead(Busy) == LOW) { 155 delay(1); // >>while SLAVE busy, don't continue. 156 } 157 digitalWrite((Takt), 0); 158 //START Sensor affects 2 umbrellas, second umbrella is set 159 if(NumberEffect[WhichSensor] == 2){ 160 delay(secondUmbrellaDelay); //Short Delay until 2nd umbrella reacts. 161 while (digitalRead(Busy) == HIGH) { 162 delay(1); // >>while SLAVE busy, don't continue. 163 } 164 //START Setting PAU for current Umbrella (NrUmbrella)// 165 digitalWrite(DO_PAU[0], (PAU[(((EffectedUmbrella[WhichSensor+20])* 6) + 0)]) ); 166 digitalWrite(DO_PAU[1], (PAU[(((EffectedUmbrella[WhichSensor+20])* 6) + 1)]) ); 167 digitalWrite(DO_PAU[2], (PAU[(((EffectedUmbrella[WhichSensor+20])* 6) + 2)]) ); 168 digitalWrite(DO_PAU[3], (PAU[(((EffectedUmbrella[WhichSensor+20])* 6) + 3)]) ); 169 digitalWrite(DO_PAU[4], (PAU[(((EffectedUmbrella[WhichSensor+20])* 6) + 4)]) ); 170 digitalWrite(DO_PAU[5], (PAU[(((EffectedUmbrella[WhichSensor+20])* 6) + 5)]) ); 171 //END Setting PAU per Umbrella// 172 if (CurrentSensorData[WhichSensor] == 1) { 173 digitalWrite((Data), 1); //Set Data for Slave. 174 } else { 175 digitalWrite((Data), 0); 176 } 177 digitalWrite((Takt), 1); //Now the date is ready to be read by SLAVE 178 //AS SOON AS SLAVE STARTS READING DATA (>> BUSY > HIGH), TAKT > 0. WAIT FOR IT. 179 while (digitalRead(Busy) == LOW) { 180 delay(1); // >>while SLAVE busy, don't continue. 181 } 182 digitalWrite((Takt), 0); 183 } 184 //END Sensor affects 2 umbrella, second umbrella is set 185 } 186 187 188 //START switching to next sensor after the previous one got checked 189 if (WhichSensor < 19) { 190 WhichSensor++; 191 } else { 192 WhichSensor = 0; 193 } 194 195 //END switching to next sensor after the previous one got checked 196} 197 198 199
MASTER
arduino
The Master is checking all PIR sensors
1/*LAST CHANGES 2017-10-26 2 * /*THIS IS THE MASTER! 3 This programm is setting the communication pins (Master > Slave) 4 for each of the 35 umbrellas*/ 5//PAU = PinAssignmentUmbrella 6//----------------------------------------------------------------------// 7//----------------------------------------------------------------------// 8//----------------------------------------------------------------------// 9/*START defining global Master-Slave Outputs*/ 10int DO_PAU[6] = {14, 15, 16, 17, 18, 19}; //ARDUINO PINs: Digital outputs for PAU communication 11int Takt = 1; //ARDUINO PIN 1: Takt manages whether SLAVE listens (if HIGH, Slave listens) 12int Data = 20; //ARDUINO PIN 20: Data indicates whether umbrella should be closed (LOW) or opened (HIGH) 13int Busy = 21; //ARDUINO PIN 21: Busy indicates whether Slave is Busy with reading PAUS (HIGH) or finished (LOW) 14/*END defining globalMaster-Slave Outputs*/ 15//----------------------------------------------------------------------// 16/*START UmbrellaSetPins INT*/ 17int PAU[] = {//Pin assignment for each umbrella 18 1, 0, 0, 0, 0, 0, //1 19 0, 1, 0, 0, 0, 0, //2 20 1, 1, 0, 0, 0, 0, //3 21 0, 0, 1, 0, 0, 0, //4 22 1, 0, 1, 0, 0, 0, //5 23 0, 1, 1, 0, 0, 0, //6 24 1, 1, 1, 0, 0, 0, //7 25 0, 0, 0, 1, 0, 0, //8 26 1, 0, 0, 1, 0, 0, //9 27 0, 1, 0, 1, 0, 0, //10 28 1, 1, 0, 1, 0, 0, //11 29 0, 0, 1, 1, 0, 0, //12 30 1, 0, 1, 1, 0, 0, //13 31 0, 1, 1, 1, 0, 0, //14 32 1, 1, 1, 1, 0, 0, //15 33 0, 0, 0, 0, 1, 0, //16 34 1, 0, 0, 0, 1, 0, //17 35 0, 1, 0, 0, 1, 0, //18 36 1, 1, 0, 0, 1, 0, //19 37 0, 0, 1, 0, 1, 0, //20 38 1, 0, 1, 0, 1, 0, //21 39 0, 1, 1, 0, 1, 0, //22 40 1, 1, 1, 0, 1, 0, //23 41 0, 0, 0, 1, 1, 0, //24 42 1, 0, 0, 1, 1, 0, //25 43 0, 1, 0, 1, 1, 0, //26 44 1, 1, 0, 1, 1, 0, //27 45 0, 0, 1, 1, 1, 0, //28 46 1, 0, 1, 1, 1, 0, //29 47 0, 1, 1, 1, 1, 0, //30 48 1, 1, 1, 1, 1, 0, //31 49 0, 0, 0, 0, 0, 1, //32 50 1, 0, 0, 0, 0, 1, //33 51 0, 1, 0, 0, 0, 1, //34 52 1, 1, 0, 0, 0, 1 //35 53}; 54int NumberEffect[20] = {1, 2, 2, 2, 1, 2, 2, 2, 1, 2, 2, 2, 1, 2, 2, 2, 1, 2, 2, 2}; //How many umbrellas does the sensor effect? 55int EffectedUmbrella[40] = {0,10,1,11,2,12,3,13,4,14,5,15,6,16,7,17,8,18,9,19,0,20,30,21,0,22,31,23,0,24,32,25,0,26,33,27,0,28,34,29}; 56/*END UmbrellaSetPins INT*/ 57//----------------------------------------------------------------------// 58/*To be adapted: FPS for SensorChecking*/ 59int DurationSensorChecking = 5000; //Duration in FPS for Trigger > Echo 60//int DurationSensorChecking = 30000; //Duration in FPS for Trigger > Echo 61int SecurityDelaySensor = 50; //Wait between two sensors for safety reasons to avoid interference. 62//----------------------------------------------------------------------// 63/*START ints for all Sensor-Changes*/ 64int SensorChange[20] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; //Indicates whether a sensor changes its Data and therefore needs umbrella action 65int CurrentSensorData[20] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; //Managed by the actual sensors > Sth Detected = 1 / Nothing detected = 0 66int PreviousSensorData[20] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; //Saved data from previous checking 67/*END ints for all Sensor-Changes*/ 68//----------------------------------------------------------------------// 69/*START defining Sensor ARDUINO Pins*/ 70int SensorTrigger[20] = {3, 5, 7, 9, 11, 13, 24, 28, 32, 36, 40, 44, 48, 52, 25, 29, 33, 37, 41, 45}; //ARDUINO PINs: Digital Outputs 71int SensorEcho[20] = {2, 4, 6, 8, 10, 12, 22, 26, 30, 34, 38, 42, 46, 50, 23, 27, 31, 35, 39, 43}; //ARDUINO PINs: Digital Inputs 72/*END defining Sensor ARDUINO Pins*/ 73int WhichSensor = 0; 74int AllSensorsNull = 0; 75boolean newStart = true; 76/*DelayCounter so that Umbrella stays open some time*/ 77int DelayCounterUmbrella[20] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; //Stores delay for each umbrella 78int DelayCounter = 5000; //Delay tbd. 79int secondUmbrellaDelay = 300; //Delay until 2nd Umbrella reacts. 80//----------------------------------------------------------------------// 81//----------------------------------------------------------------------// 82//----------------------------------------------------------------------// 83void setup() { 84 //Serial.begin(9600); 85 Serial.end(); 86 Serial1.end(); 87 Serial2.end(); 88 Serial3.end(); 89 //START Defining all communication pins// 90 for (int x = 0; x < 6; x++) { //Declaring all 6 DO-PAUs as Digital Outputs 91 pinMode(DO_PAU[x], OUTPUT); 92 digitalWrite(DO_PAU[x], LOW);//Setting all 6 DO-PAUs to LOW 93 } 94 pinMode(Takt, OUTPUT); digitalWrite(Takt, LOW); 95 pinMode(Data, OUTPUT); digitalWrite(Data, LOW); 96 pinMode(Busy, INPUT); 97 //END Defining all communication pins// 98 //START Defining all ARDUINO sensor pins// 99 for (int x = 0; x < 20; x++) { //Declaring all Trigger Pins as Digital Output, Echo as Digital Input 100 pinMode(SensorTrigger[x], OUTPUT); digitalWrite(SensorTrigger[x], LOW); 101 pinMode(SensorEcho[x], INPUT); 102 } 103 //END Defining all ARDUINO sensor pins// 104} 105//----------------------------------------------------------------------// 106//----------------------------------------------------------------------// 107//----------------------------------------------------------------------// 108void loop() { 109 if (newStart == true){ 110 newStart = false; 111 delay(1000); 112 } 113 //START Checking Sensor [WhichSensor] for x FPS 114 if(digitalRead(SensorEcho[WhichSensor]) == HIGH){CurrentSensorData[WhichSensor] = 1; 115 DelayCounterUmbrella[WhichSensor] = 0;} 116 else { 117 if(DelayCounterUmbrella[WhichSensor] == DelayCounter){ 118 CurrentSensorData[WhichSensor] = 0; 119 } 120 else{DelayCounterUmbrella[WhichSensor]++;} 121 } 122 //END Checking Sensor [WhichSensor] for x FPS 123 //START Checking if something changed regarding the current sensor 124 if (CurrentSensorData[WhichSensor] == PreviousSensorData[WhichSensor]) { 125 SensorChange[WhichSensor] = 0; 126 } 127 else { 128 SensorChange[WhichSensor] = 1; 129 } 130 131 //END Checking if something changed regarding the current sensor 132 //START communicating Change to SLAVE 133 if (SensorChange[WhichSensor] == 1) { // if change = true, start communication 134 while (digitalRead(Busy) == HIGH) { 135 delay(1); // >>while SLAVE busy, don't continue. 136 } 137 //START Setting PAU for current Umbrella (NrUmbrella)// 138 digitalWrite(DO_PAU[0], (PAU[(((EffectedUmbrella[WhichSensor])* 6) + 0)]) ); 139 digitalWrite(DO_PAU[1], (PAU[(((EffectedUmbrella[WhichSensor])* 6) + 1)]) ); 140 digitalWrite(DO_PAU[2], (PAU[(((EffectedUmbrella[WhichSensor])* 6) + 2)]) ); 141 digitalWrite(DO_PAU[3], (PAU[(((EffectedUmbrella[WhichSensor])* 6) + 3)]) ); 142 digitalWrite(DO_PAU[4], (PAU[(((EffectedUmbrella[WhichSensor])* 6) + 4)]) ); 143 digitalWrite(DO_PAU[5], (PAU[(((EffectedUmbrella[WhichSensor])* 6) + 5)]) ); 144 //END Setting PAU per Umbrella// 145 if (CurrentSensorData[WhichSensor] == 1) { 146 digitalWrite((Data), 1); //Set Data for Slave. 147 } else { 148 digitalWrite((Data), 0); 149 } 150 PreviousSensorData[WhichSensor] = CurrentSensorData[WhichSensor]; //"Previous state" is now the current one 151 SensorChange[WhichSensor] = 0; //There's no current change on this sensor 152 digitalWrite((Takt), 1); //Now the date is ready to be read by SLAVE 153 //AS SOON AS SLAVE STARTS READING DATA (>> BUSY > HIGH), TAKT > 0. WAIT FOR IT. 154 while (digitalRead(Busy) == LOW) { 155 delay(1); // >>while SLAVE busy, don't continue. 156 } 157 digitalWrite((Takt), 0); 158 //START Sensor affects 2 umbrellas, second umbrella is set 159 if(NumberEffect[WhichSensor] == 2){ 160 delay(secondUmbrellaDelay); //Short Delay until 2nd umbrella reacts. 161 while (digitalRead(Busy) == HIGH) { 162 delay(1); // >>while SLAVE busy, don't continue. 163 } 164 //START Setting PAU for current Umbrella (NrUmbrella)// 165 digitalWrite(DO_PAU[0], (PAU[(((EffectedUmbrella[WhichSensor+20])* 6) + 0)]) ); 166 digitalWrite(DO_PAU[1], (PAU[(((EffectedUmbrella[WhichSensor+20])* 6) + 1)]) ); 167 digitalWrite(DO_PAU[2], (PAU[(((EffectedUmbrella[WhichSensor+20])* 6) + 2)]) ); 168 digitalWrite(DO_PAU[3], (PAU[(((EffectedUmbrella[WhichSensor+20])* 6) + 3)]) ); 169 digitalWrite(DO_PAU[4], (PAU[(((EffectedUmbrella[WhichSensor+20])* 6) + 4)]) ); 170 digitalWrite(DO_PAU[5], (PAU[(((EffectedUmbrella[WhichSensor+20])* 6) + 5)]) ); 171 //END Setting PAU per Umbrella// 172 if (CurrentSensorData[WhichSensor] == 1) { 173 digitalWrite((Data), 1); //Set Data for Slave. 174 } else { 175 digitalWrite((Data), 0); 176 } 177 digitalWrite((Takt), 1); //Now the date is ready to be read by SLAVE 178 //AS SOON AS SLAVE STARTS READING DATA (>> BUSY > HIGH), TAKT > 0. WAIT FOR IT. 179 while (digitalRead(Busy) == LOW) { 180 delay(1); // >>while SLAVE busy, don't continue. 181 } 182 digitalWrite((Takt), 0); 183 } 184 //END Sensor affects 2 umbrella, second umbrella is set 185 } 186 187 188 //START switching to next sensor after the previous one got checked 189 if (WhichSensor < 19) { 190 WhichSensor++; 191 } else { 192 WhichSensor = 0; 193 } 194 195 //END switching to next sensor after the previous one got checked 196} 197 198 199
SLAVE
arduino
The Slave is controlling all umbrellas.
1/*LAST CHANGES 2017-10-26 2 _20171026_SLAVE_SLAVE_DurationOpening 3 */ 4/*THIS IS THE SLAVE! 5 This programm plays each single umbrellas it receives from the Master 6/* 7//PAU = PinAssignmentUmbrella 8//----------------------------------------------------------------------// 9//----------------------------------------------------------------------// 10//----------------------------------------------------------------------// 11int WaitForSglUmbrella = 2000; 12/*START defining global Master-Slave Outputs*/ 13int DO_PAU[6] = {14, 15, 16, 17, 18, 19}; //ARDUINO PINs: Digital outputs for PAU communication 14int Takt = 1; //ARDUINO PIN 1: Takt manages whether SLAVE listens (if HIGH, Slave listens) 15int Data = 20; //ARDUINO PIN 20: Data indicates whether umbrella should be closed (LOW) or opened (HIGH) 16int Busy = 21; //ARDUINO PIN 21: Busy indicates whether Slave is Busy with reading PAUS (HIGH) or finished (LOW) 17/*END defining globalMaster-Slave Outputs*/ 18/*START defining Umbrelal ARDUINO Pins*/ 19int UmbrellaPin[35] = {2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 44, 46, 48, 50, 52, 23, 25, 27, 29, 31, 33, 35}; //ARDUINO PINs: Digital Outputs 20/*END defining Umbrelal ARDUINO Pins*/ 21boolean JERKPROGRAMM = false; //Special programm if all 22int SumOfAllPAUs = 0; //Sum of all PAUs >> Indicates which umbrella it is about 23int WhichUmbrella[35] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; 24/*START INT FOR JERK PROGRAMM*/ 25int JerkWasRunning = 0; 26long DelayTillNextJerk; //Delay till next umbrella jerks 27int DelayTillNextJerkCounter = 0; 28int DelayTillNextJerkMIN = 10000; //min FPS till next umbrella jerks 29int DelayTillNextJerkMAX = 500000; //max FPS till next umbrella jerks 30long JerkUmbrella; //Will store the PIN of the JerkUmbrella 31int DurationJerkUmbrella = 200; //Duration of which jerking umbrella closes 32int CountingWhileJerking = 0; //Counter till Umbrella stops jerking 33/*END INT FOR JERK PROGRAMM*/ 34boolean newStart = true; 35//----------------------------------------------------------------------// 36//----------------------------------------------------------------------// 37//----------------------------------------------------------------------// 38void setup() { 39 //Serial.begin(9600); 40 Serial.end(); 41 Serial1.end(); 42 Serial2.end(); 43 Serial3.end(); 44 45 //randomSeed(analogRead(0));//for my Random numbers; 46 //START Defining all communication pins// 47 for (int x = 0; x < 6; x++) { //Declaring all 6 DO-PAUs as Digital Inputs 48 pinMode(DO_PAU[x], INPUT); 49 } 50 pinMode(Takt, INPUT); 51 pinMode(Data, INPUT); 52 pinMode(Busy, OUTPUT); digitalWrite(Busy, LOW); 53 //END Defining all communication pins// 54 //START Defining all ARDUINO sensor pins// 55 for (int x = 0; x < 35; x++) { //Declaring all Umbrella Pins as Digital Output 56 pinMode(UmbrellaPin[x], OUTPUT); digitalWrite(UmbrellaPin[x], LOW); 57 } 58 //END Defining all ARDUINO sensor pins// 59} 60//----------------------------------------------------------------------// 61//----------------------------------------------------------------------// 62//----------------------------------------------------------------------// 63void loop() { 64 if (newStart == true){ 65 newStart = false; 66 delay(4000); 67 } 68 //START Receive Data from Master + set single Umbrella 69 if(digitalRead(Takt) == 1){ //Data is ready to be processed 70 digitalWrite(Busy, 1); //Now SLAVE is busy reading data 71 SumOfAllPAUs = -1;//Umbrella Array starts with 0! 72 if(digitalRead(DO_PAU[0]) == HIGH){SumOfAllPAUs = SumOfAllPAUs+1;} 73 if(digitalRead(DO_PAU[1]) == HIGH){SumOfAllPAUs = SumOfAllPAUs+2;} 74 if(digitalRead(DO_PAU[2]) == HIGH){SumOfAllPAUs = SumOfAllPAUs+4;} 75 if(digitalRead(DO_PAU[3]) == HIGH){SumOfAllPAUs = SumOfAllPAUs+8;} 76 if(digitalRead(DO_PAU[4]) == HIGH){SumOfAllPAUs = SumOfAllPAUs+16;} 77 if(digitalRead(DO_PAU[5]) == HIGH){SumOfAllPAUs = SumOfAllPAUs+32;} 78 //START Set Umbrella/JERK Data 79 80 if(digitalRead(Data) == 1){WhichUmbrella[SumOfAllPAUs] = 1;} 81 else{WhichUmbrella[SumOfAllPAUs] = 0;} 82 //END Set Umbrella/JERK Data 83 84 //END Receive Data from Master 85 86 //START Setting Single Umbrella 87 88 89 digitalWrite(UmbrellaPin[SumOfAllPAUs], (WhichUmbrella[SumOfAllPAUs]));//Open or Closes Umbrella 90 91 digitalWrite(Busy, 0); //Now SLAVE is finished with reading and setting data 92//END Setting Single Umbrella 93} 94 95} 96 97 98 99
Downloadable files
PIR Signal Inverter
A Inverter for the PIR Signal to avoid disturbance
PIR Signal Inverter
Comments
Only logged in users can leave comments