/* This is for the first two gateways: A and B. */ // this constant won't change: const int ain = 44; //pin 44 is the first digital input for Gate A const int aout = 45;// pin 45 is the second digital input for Gate A const int bin = 42; // same for Gate B const int bout = 43; // same for Gate B // Variables will change: int ins = 0; // counts ins and outs int outs = 0; int ai = 0; // Gate A 1st pin status int lai = 0; // Gate A last status of 1st pin int ao = 0; // Gate A 2nd pin status int lao = 0; // Gate A last status of 2nd pin int bi = 0; int lbi = 0; int bo = 0; int lbo = 0; int count = 0; // this just tests if there has been a change in our bee count int lcount = 0; void setup() { // initialize the button pin as a input: pinMode(ain, INPUT); pinMode(aout, INPUT); pinMode(bin, INPUT); pinMode(bout, INPUT); // initialize serial communication: Serial.begin(38400); //a bit different than the Arduino here.... 38400 } void loop() { // read the pushbutton input pin: ai = digitalRead(ain); ao = digitalRead(aout); bi = digitalRead(bin); bo = digitalRead(bout); if (lai != ai){ // has the status if the 1st pin changed? if (ai > ao) { // if yes, is the bee going in or out? ins++; // if its going in add one bee to ins }} if (lao != ao){ if (ao > ai) { outs++; }} if (lbi != bi){ if (bi > bo) { ins++; }} if (lbo != bo){ if (bo > bi) { outs++; }} lai = ai; // updates the last status lao = ao; lbi = bi; lbo = bo; count = ins + outs; if (lcount != count){ // if the count has changed we print the new count Serial.print("number In: "); Serial.println(ins); Serial.print("number Out: "); Serial.println(outs); lcount = count; } }