SURFACE X
SURFACE X is an interactive installation focusing on the moment when the self-created digital and our physical identities collide.
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 4 is setting the communication pins (Master > Slave) 5 for each of the 35 umbrellas*/ 6//PAU 7 = PinAssignmentUmbrella 8//----------------------------------------------------------------------// 9//----------------------------------------------------------------------// 10//----------------------------------------------------------------------// 11/*START 12 defining global Master-Slave Outputs*/ 13int DO_PAU[6] = {14, 15, 16, 17, 18, 19}; 14 //ARDUINO PINs: Digital outputs for PAU communication 15int Takt = 1; //ARDUINO 16 PIN 1: Takt manages whether SLAVE listens (if HIGH, Slave listens) 17int Data = 18 20; //ARDUINO PIN 20: Data indicates whether umbrella should be closed (LOW) or 19 opened (HIGH) 20int Busy = 21; //ARDUINO PIN 21: Busy indicates whether Slave is 21 Busy with reading PAUS (HIGH) or finished (LOW) 22/*END defining globalMaster-Slave 23 Outputs*/ 24//----------------------------------------------------------------------// 25/*START 26 UmbrellaSetPins INT*/ 27int PAU[] = {//Pin assignment for each umbrella 28 1, 29 0, 0, 0, 0, 0, //1 30 0, 1, 0, 0, 0, 0, //2 31 1, 1, 0, 0, 0, 0, //3 32 0, 33 0, 1, 0, 0, 0, //4 34 1, 0, 1, 0, 0, 0, //5 35 0, 1, 1, 0, 0, 0, //6 36 1, 37 1, 1, 0, 0, 0, //7 38 0, 0, 0, 1, 0, 0, //8 39 1, 0, 0, 1, 0, 0, //9 40 0, 41 1, 0, 1, 0, 0, //10 42 1, 1, 0, 1, 0, 0, //11 43 0, 0, 1, 1, 0, 0, //12 44 45 1, 0, 1, 1, 0, 0, //13 46 0, 1, 1, 1, 0, 0, //14 47 1, 1, 1, 1, 0, 0, //15 48 49 0, 0, 0, 0, 1, 0, //16 50 1, 0, 0, 0, 1, 0, //17 51 0, 1, 0, 0, 1, 0, //18 52 53 1, 1, 0, 0, 1, 0, //19 54 0, 0, 1, 0, 1, 0, //20 55 1, 0, 1, 0, 1, 0, //21 56 57 0, 1, 1, 0, 1, 0, //22 58 1, 1, 1, 0, 1, 0, //23 59 0, 0, 0, 1, 1, 0, //24 60 61 1, 0, 0, 1, 1, 0, //25 62 0, 1, 0, 1, 1, 0, //26 63 1, 1, 0, 1, 1, 0, //27 64 65 0, 0, 1, 1, 1, 0, //28 66 1, 0, 1, 1, 1, 0, //29 67 0, 1, 1, 1, 1, 0, //30 68 69 1, 1, 1, 1, 1, 0, //31 70 0, 0, 0, 0, 0, 1, //32 71 1, 0, 0, 0, 0, 1, //33 72 73 0, 1, 0, 0, 0, 1, //34 74 1, 1, 0, 0, 0, 1 //35 75}; 76int NumberEffect[20] 77 = {1, 2, 2, 2, 1, 2, 2, 2, 1, 2, 2, 2, 1, 2, 2, 2, 1, 2, 2, 2}; //How many umbrellas 78 does the sensor effect? 79int 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}; 80/*END 81 UmbrellaSetPins INT*/ 82//----------------------------------------------------------------------// 83/*To 84 be adapted: FPS for SensorChecking*/ 85int DurationSensorChecking = 5000; //Duration 86 in FPS for Trigger > Echo 87//int DurationSensorChecking = 30000; //Duration in 88 FPS for Trigger > Echo 89int SecurityDelaySensor = 50; //Wait between two sensors 90 for safety reasons to avoid interference. 91//----------------------------------------------------------------------// 92/*START 93 ints for all Sensor-Changes*/ 94int SensorChange[20] = {0, 0, 0, 0, 0, 0, 0, 0, 95 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; //Indicates whether a sensor changes its Data 96 and therefore needs umbrella action 97int CurrentSensorData[20] = {0, 0, 0, 0, 98 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; //Managed by the actual sensors 99 > Sth Detected = 1 / Nothing detected = 0 100int PreviousSensorData[20] = {0, 0, 101 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; //Saved data from previous 102 checking 103/*END ints for all Sensor-Changes*/ 104//----------------------------------------------------------------------// 105/*START 106 defining Sensor ARDUINO Pins*/ 107int SensorTrigger[20] = {3, 5, 7, 9, 11, 13, 24, 108 28, 32, 36, 40, 44, 48, 52, 25, 29, 33, 37, 41, 45}; //ARDUINO PINs: Digital Outputs 109int 110 SensorEcho[20] = {2, 4, 6, 8, 10, 12, 22, 26, 30, 34, 38, 42, 46, 50, 23, 27, 31, 111 35, 39, 43}; //ARDUINO PINs: Digital Inputs 112/*END defining Sensor ARDUINO Pins*/ 113int 114 WhichSensor = 0; 115int AllSensorsNull = 0; 116boolean newStart = true; 117/*DelayCounter 118 so that Umbrella stays open some time*/ 119int DelayCounterUmbrella[20] = {0, 0, 120 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; //Stores delay for each umbrella 121int 122 DelayCounter = 5000; //Delay tbd. 123int secondUmbrellaDelay = 300; //Delay until 124 2nd Umbrella reacts. 125//----------------------------------------------------------------------// 126//----------------------------------------------------------------------// 127//----------------------------------------------------------------------// 128void 129 setup() { 130 //Serial.begin(9600); 131 Serial.end(); 132 Serial1.end(); 133 134 Serial2.end(); 135 Serial3.end(); 136 //START Defining all communication pins// 137 138 for (int x = 0; x < 6; x++) { //Declaring all 6 DO-PAUs as Digital Outputs 139 140 pinMode(DO_PAU[x], OUTPUT); 141 digitalWrite(DO_PAU[x], LOW);//Setting all 142 6 DO-PAUs to LOW 143 } 144 pinMode(Takt, OUTPUT); digitalWrite(Takt, LOW); 145 146 pinMode(Data, OUTPUT); digitalWrite(Data, LOW); 147 pinMode(Busy, INPUT); 148 149 //END Defining all communication pins// 150 //START Defining all ARDUINO sensor 151 pins// 152 for (int x = 0; x < 20; x++) { //Declaring all Trigger Pins as Digital 153 Output, Echo as Digital Input 154 pinMode(SensorTrigger[x], OUTPUT); digitalWrite(SensorTrigger[x], 155 LOW); 156 pinMode(SensorEcho[x], INPUT); 157 } 158 //END Defining all ARDUINO 159 sensor pins// 160} 161//----------------------------------------------------------------------// 162//----------------------------------------------------------------------// 163//----------------------------------------------------------------------// 164void 165 loop() { 166 if (newStart == true){ 167 newStart = false; 168 delay(1000); 169 170 } 171 //START Checking Sensor [WhichSensor] for x FPS 172 if(digitalRead(SensorEcho[WhichSensor]) 173 == HIGH){CurrentSensorData[WhichSensor] = 1; 174 DelayCounterUmbrella[WhichSensor] 175 = 0;} 176 else { 177 if(DelayCounterUmbrella[WhichSensor] == DelayCounter){ 178 179 CurrentSensorData[WhichSensor] = 0; 180 } 181 else{DelayCounterUmbrella[WhichSensor]++;} 182 183 } 184 //END Checking Sensor [WhichSensor] for x FPS 185 //START Checking 186 if something changed regarding the current sensor 187 if (CurrentSensorData[WhichSensor] 188 == PreviousSensorData[WhichSensor]) { 189 SensorChange[WhichSensor] = 0; 190 191 } 192 else { 193 SensorChange[WhichSensor] = 1; 194 } 195 196 //END Checking 197 if something changed regarding the current sensor 198 //START communicating Change 199 to SLAVE 200 if (SensorChange[WhichSensor] == 1) { // if change = true, start communication 201 202 while (digitalRead(Busy) == HIGH) { 203 delay(1); // >>while SLAVE busy, 204 don't continue. 205 } 206 //START Setting PAU for current Umbrella (NrUmbrella)// 207 208 digitalWrite(DO_PAU[0], (PAU[(((EffectedUmbrella[WhichSensor])* 6) + 0)]) ); 209 210 digitalWrite(DO_PAU[1], (PAU[(((EffectedUmbrella[WhichSensor])* 6) + 1)]) ); 211 212 digitalWrite(DO_PAU[2], (PAU[(((EffectedUmbrella[WhichSensor])* 6) + 2)]) ); 213 214 digitalWrite(DO_PAU[3], (PAU[(((EffectedUmbrella[WhichSensor])* 6) + 3)]) ); 215 216 digitalWrite(DO_PAU[4], (PAU[(((EffectedUmbrella[WhichSensor])* 6) + 4)]) ); 217 218 digitalWrite(DO_PAU[5], (PAU[(((EffectedUmbrella[WhichSensor])* 6) + 5)]) ); 219 220 //END Setting PAU per Umbrella// 221 if (CurrentSensorData[WhichSensor] == 222 1) { 223 digitalWrite((Data), 1); //Set Data for Slave. 224 } else { 225 226 digitalWrite((Data), 0); 227 } 228 PreviousSensorData[WhichSensor] = 229 CurrentSensorData[WhichSensor]; //"Previous state" is now the current one 230 231 SensorChange[WhichSensor] = 0; //There's no current change on this sensor 232 233 digitalWrite((Takt), 1); //Now the date is ready to be read by SLAVE 234 //AS 235 SOON AS SLAVE STARTS READING DATA (>> BUSY > HIGH), TAKT > 0. WAIT FOR IT. 236 while 237 (digitalRead(Busy) == LOW) { 238 delay(1); // >>while SLAVE busy, don't continue. 239 240 } 241 digitalWrite((Takt), 0); 242 //START Sensor affects 2 umbrellas, 243 second umbrella is set 244 if(NumberEffect[WhichSensor] == 2){ 245 delay(secondUmbrellaDelay); 246 //Short Delay until 2nd umbrella reacts. 247 while (digitalRead(Busy) == 248 HIGH) { 249 delay(1); // >>while SLAVE busy, don't continue. 250 } 251 //START 252 Setting PAU for current Umbrella (NrUmbrella)// 253 digitalWrite(DO_PAU[0], (PAU[(((EffectedUmbrella[WhichSensor+20])* 254 6) + 0)]) ); 255 digitalWrite(DO_PAU[1], (PAU[(((EffectedUmbrella[WhichSensor+20])* 256 6) + 1)]) ); 257 digitalWrite(DO_PAU[2], (PAU[(((EffectedUmbrella[WhichSensor+20])* 258 6) + 2)]) ); 259 digitalWrite(DO_PAU[3], (PAU[(((EffectedUmbrella[WhichSensor+20])* 260 6) + 3)]) ); 261 digitalWrite(DO_PAU[4], (PAU[(((EffectedUmbrella[WhichSensor+20])* 262 6) + 4)]) ); 263 digitalWrite(DO_PAU[5], (PAU[(((EffectedUmbrella[WhichSensor+20])* 264 6) + 5)]) ); 265 //END Setting PAU per Umbrella// 266 if (CurrentSensorData[WhichSensor] 267 == 1) { 268 digitalWrite((Data), 1); //Set Data for Slave. 269 } else { 270 271 digitalWrite((Data), 0); 272 } 273 digitalWrite((Takt), 1); //Now the 274 date is ready to be read by SLAVE 275 //AS SOON AS SLAVE STARTS READING DATA 276 (>> BUSY > HIGH), TAKT > 0. WAIT FOR IT. 277 while (digitalRead(Busy) == LOW) 278 { 279 delay(1); // >>while SLAVE busy, don't continue. 280 } 281 digitalWrite((Takt), 282 0); 283 } 284 //END Sensor affects 2 umbrella, second umbrella is set 285 286 } 287 288 289 //START switching to next sensor after the previous one got 290 checked 291 if (WhichSensor < 19) { 292 WhichSensor++; 293 } else { 294 WhichSensor 295 = 0; 296 } 297 298 //END switching to next sensor after the previous one got checked 299} 300 301 302
SLAVE
arduino
The Slave is controlling all umbrellas.
1/*LAST CHANGES 2017-10-26 2 _20171026_SLAVE_SLAVE_DurationOpening 3 4 */ 5/*THIS IS THE SLAVE! 6 This programm plays each single umbrellas it receives 7 from the Master 8/* 9//PAU = PinAssignmentUmbrella 10//----------------------------------------------------------------------// 11//----------------------------------------------------------------------// 12//----------------------------------------------------------------------// 13int 14 WaitForSglUmbrella = 2000; 15/*START defining global Master-Slave Outputs*/ 16int 17 DO_PAU[6] = {14, 15, 16, 17, 18, 19}; //ARDUINO PINs: Digital outputs for PAU communication 18int 19 Takt = 1; //ARDUINO PIN 1: Takt manages whether SLAVE listens (if HIGH, Slave listens) 20int 21 Data = 20; //ARDUINO PIN 20: Data indicates whether umbrella should be closed (LOW) 22 or opened (HIGH) 23int Busy = 21; //ARDUINO PIN 21: Busy indicates whether Slave 24 is Busy with reading PAUS (HIGH) or finished (LOW) 25/*END defining globalMaster-Slave 26 Outputs*/ 27/*START defining Umbrelal ARDUINO Pins*/ 28int UmbrellaPin[35] = {2, 29 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 30 44, 46, 48, 50, 52, 23, 25, 27, 29, 31, 33, 35}; //ARDUINO PINs: Digital Outputs 31/*END 32 defining Umbrelal ARDUINO Pins*/ 33boolean JERKPROGRAMM = false; //Special programm 34 if all 35int SumOfAllPAUs = 0; //Sum of all PAUs >> Indicates which umbrella it 36 is about 37int WhichUmbrella[35] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 38 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; 39/*START INT FOR 40 JERK PROGRAMM*/ 41int JerkWasRunning = 0; 42long DelayTillNextJerk; //Delay till 43 next umbrella jerks 44int DelayTillNextJerkCounter = 0; 45int DelayTillNextJerkMIN 46 = 10000; //min FPS till next umbrella jerks 47int DelayTillNextJerkMAX = 500000; 48 //max FPS till next umbrella jerks 49long JerkUmbrella; //Will store the PIN of 50 the JerkUmbrella 51int DurationJerkUmbrella = 200; //Duration of which jerking 52 umbrella closes 53int CountingWhileJerking = 0; //Counter till Umbrella stops jerking 54/*END 55 INT FOR JERK PROGRAMM*/ 56boolean newStart = true; 57//----------------------------------------------------------------------// 58//----------------------------------------------------------------------// 59//----------------------------------------------------------------------// 60void 61 setup() { 62 //Serial.begin(9600); 63 Serial.end(); 64 Serial1.end(); 65 66 Serial2.end(); 67 Serial3.end(); 68 69 //randomSeed(analogRead(0));//for 70 my Random numbers; 71 //START Defining all communication pins// 72 for (int 73 x = 0; x < 6; x++) { //Declaring all 6 DO-PAUs as Digital Inputs 74 pinMode(DO_PAU[x], 75 INPUT); 76 } 77 pinMode(Takt, INPUT); 78 pinMode(Data, INPUT); 79 pinMode(Busy, 80 OUTPUT); digitalWrite(Busy, LOW); 81 //END Defining all communication pins// 82 83 //START Defining all ARDUINO sensor pins// 84 for (int x = 0; x < 35; x++) { 85 //Declaring all Umbrella Pins as Digital Output 86 pinMode(UmbrellaPin[x], OUTPUT); 87 digitalWrite(UmbrellaPin[x], LOW); 88 } 89 //END Defining all ARDUINO sensor 90 pins// 91} 92//----------------------------------------------------------------------// 93//----------------------------------------------------------------------// 94//----------------------------------------------------------------------// 95void 96 loop() { 97 if (newStart == true){ 98 newStart = false; 99 delay(4000); 100 101 } 102 //START Receive Data from Master + set single Umbrella 103 if(digitalRead(Takt) 104 == 1){ //Data is ready to be processed 105 digitalWrite(Busy, 1); //Now SLAVE 106 is busy reading data 107 SumOfAllPAUs = -1;//Umbrella Array starts with 0! 108 109 if(digitalRead(DO_PAU[0]) == HIGH){SumOfAllPAUs = SumOfAllPAUs+1;} 110 if(digitalRead(DO_PAU[1]) 111 == HIGH){SumOfAllPAUs = SumOfAllPAUs+2;} 112 if(digitalRead(DO_PAU[2]) == HIGH){SumOfAllPAUs 113 = SumOfAllPAUs+4;} 114 if(digitalRead(DO_PAU[3]) == HIGH){SumOfAllPAUs = SumOfAllPAUs+8;} 115 116 if(digitalRead(DO_PAU[4]) == HIGH){SumOfAllPAUs = SumOfAllPAUs+16;} 117 if(digitalRead(DO_PAU[5]) 118 == HIGH){SumOfAllPAUs = SumOfAllPAUs+32;} 119 //START Set Umbrella/JERK Data 120 121 122 if(digitalRead(Data) == 1){WhichUmbrella[SumOfAllPAUs] = 1;} 123 else{WhichUmbrella[SumOfAllPAUs] 124 = 0;} 125 //END Set Umbrella/JERK Data 126 127 //END Receive Data from Master 128 129 130 //START Setting Single Umbrella 131 132 133 digitalWrite(UmbrellaPin[SumOfAllPAUs], 134 (WhichUmbrella[SumOfAllPAUs]));//Open or Closes Umbrella 135 136 digitalWrite(Busy, 137 0); //Now SLAVE is finished with reading and setting data 138//END Setting Single 139 Umbrella 140} 141 142} 143 144 145 146
Downloadable files
PIR Signal Inverter
A Inverter for the PIR Signal to avoid disturbance
PIR Signal Inverter
PIR Signal Inverter
A Inverter for the PIR Signal to avoid disturbance
PIR Signal Inverter
Comments