//define PWM LEDs #define LED1 9 #define LED2 10 #define LED3 11 //create variables for sensor values int valLight=0; //create variables for light PWM num int i=0; int maxVal; int newVal; //variables for light delays int delayVal; int delayBug1, delayBug2, delayBug3; //boolean for each light boolean bug1, bug2, bug3; void setup() { Serial.begin(9600); //tell arduino lights are output pinMode(LED1, OUTPUT); pinMode(LED2, OUTPUT); pinMode(LED3, OUTPUT); } void loop(){ // set valLight to value of analog sensor valLight= analogRead(0); // lightVal to 255 and 100 -- maxNum for loop will go to maxVal= map(valLight, 0, 1023, 255, 100); //lightVal between 10 and 1 -- speed which light goes up or down newVal= map(valLight, 0, 1023, 10, 1); //lightVal number between 50 and 150 -- delay for each light delayVal= map(valLight, 0, 1023, 50, 150); //set and additional random delay for each bug delayBug1= delayVal+random(0,30); delayBug2= delayVal+random(0,30); delayBug3= delayVal+random(0,30); //set each light boolean to true or false bug1 = random(0,2); bug2 = random(0,2); bug3 = random(0,2); Serial.println (int(bug1)); //--seperate analog outputs to have them work independantly /*----- bug 1 --------*/ //if bug1 boolean is true if (bug1==1){ //write light up to max value, skip numbers based on newVal for( i=0; i0; i-=newVal){ analogWrite(9,i); delay(delayBug1); } } //All bug code based off above code /*----- bug 2 --------*/ if(bug2==1){ for( i=0; i0; i-=newVal){ analogWrite(10,i); delay(delayBug2); } } /*----- bug 3 --------*/ if (bug3==1){ for( i=0; i0; i-=newVal){ analogWrite(11,i); delay(delayBug3); } } }