Created
January 29, 2014 17:34
-
-
Save carlynorama/8692908 to your computer and use it in GitHub Desktop.
This gist is a snapshot of code in the BeeMail repository written January 28th to 29th 2014
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//This code is testing code for the circut to make sure all of the | |
//physical Arduino I/O is working. It checks a potentiometer or other | |
//sensors on the AO PIN and equates it to the future number of mails | |
//in the inbox. | |
//------------------------------------------------- OUTPUTS AND THEIR VARIABLES | |
int beePins[beeTotalNumber] = {9, 10, 11 }; | |
//INPUTS AND THEIR VARIABLES | |
int howManyNewEmails = 0; | |
//-------------------------------------------------------- GLOBAL BEE SETTINGS | |
//the number of emails the bees hit maximum freakout. | |
//ideally it should be divisible by the number of | |
//beeActivityLevels | |
int maxBeeVar = 640; | |
//how many different states the Bees can be in | |
const int beeActivityLevels = 16; | |
//the total number of bees bing controlled | |
const int beeTotalNumber = 3; | |
//the number of emails the bees hit maximum freakout. | |
//ideally it should be divisible by the number of | |
//beeActivityLevels | |
int maxBeeVar = 640; | |
//The area that dictates the 16 BeeActivityLevels. | |
int b[beeActivityLevels][beeTotalNumber] = | |
{ | |
{ 0, 0, 0 }, | |
{ 0, 0, 50 }, | |
{ 0, 50, 50 }, | |
{ 50, 50, 50 }, | |
{ 50, 50, 100 }, | |
{ 50, 100, 100 }, | |
{ 100, 100, 100 }, | |
{ 100, 100, 150 }, | |
{ 100, 150, 150 }, | |
{ 150, 150, 150 }, | |
{ 150, 150, 200 }, | |
{ 150, 200, 200 }, | |
{ 200, 200, 200 }, | |
{ 200, 200, 250 }, | |
{ 200, 250, 250 }, | |
{ 255, 255, 255 }, | |
}; | |
//---------------------------------------------------------------------- SETUP | |
void setup() { | |
Serial.begin(9600); | |
} | |
//----------------------------------------------------------------------- LOOP | |
void loop() { | |
//get the data determining bee behavior | |
howManyNewEmails = analogRead(A0); | |
//Serial.println(howManyNewEmails); | |
//update the bees | |
updateBees(howManyNewEmails, maxBeeVar); | |
//mini-pause | |
delay(10); | |
} | |
//---------------------------------------------------------------- updateBees() | |
void updateBees(int v, int maxVal) { | |
//ignore any values of V above maximum freakout level | |
v = min(v, maxVal); | |
//map the newly constrained V to the beeActivityLevel array | |
//the top value is 1 less than the number than the array size | |
//because the an array starts with the index number 0 | |
int mappedV = map(v, 0, maxVal, 0, beeActivityLevels-1); | |
//Serial.println(mappedV); | |
//for each bee, get the value it supposed to be and set it there | |
for (int i=0; i <= beeTotalNumber-1; i++){ | |
//Serial.println(b[mappedV][i]); | |
analogWrite(beePins[i], b[mappedV][i]); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment