/* This code was written for the Stitch the Loop e-textiles curriculum by the Exploring Computer Science e-textiles team. ECS 2018 GPL V3 for non commercial use. ECS 2018 CC- BY NC SA. */ /* ◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇ This program is an EXAMPLE of the many possible solutions. This code will compile as is. ◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇ */ /* STUDENT META HERE STUDENT NAME(S) Date Written Brief description of what program does here. */ // The first section is where to declare global objects and call up additional files the program needs to use. int led1 = 2; //We named each led to make it easier to code int led2 = 3; int led3 = 10; int led4 = 9; int delaytime1 = 50; int aluminumFoil = A11; //name your aluminum foil patch (only the one that's connected to an "A" pin) int foilStorage; //this variable stores readings from the sensor void setup() { // The second section is for things that only need to be done once at the beginning of the program. pinMode(led1, OUTPUT); //Set lights to outputs pinMode(led2, OUTPUT); pinMode(led3, OUTPUT); pinMode(led4, OUTPUT); pinMode(aluminumFoil, INPUT); //sets aluminum foil patch to INPUT digitalWrite(aluminumFoil, HIGH); //initializes the sensor Serial.begin(9600); //initializes the communication to the serial monitor } void loop() { /* The third section is for things that happen repeatedly in the program loop while the program is running. The code is executed in the order coded. */ foilStorage = analogRead(aluminumFoil); //the part of your code that reads information from the sensor Serial.println(foilStorage); //prints the value of the sensor to the serial monitor delay(100); //delay for 1/10 of a second if (foilStorage > 990) //Set your first condition. { LightingPattern1 (); } else if (foilStorage > 960 && foilStorage <= 990) //lightly touching { LightingPattern2 (); } else if (foilStorage > 860 && foilStorage <=960) //squeezing a little { LightingPattern3 (); } else if (foilStorage<=860) //squeezing a lot { LightingPattern4 (); } } // The fourth section is for functions that are called up by the third section. void LightingPattern1(){ //one light on digitalWrite(led1, HIGH); digitalWrite(led2, LOW); digitalWrite(led3, LOW); digitalWrite(led4, LOW); } void LightingPattern2(){ //two lights on digitalWrite(led1, HIGH); digitalWrite(led2, HIGH); digitalWrite(led3, LOW); digitalWrite(led4, LOW); } void LightingPattern3(){ //three lights on digitalWrite(led1, HIGH); digitalWrite(led2, HIGH); digitalWrite(led3, HIGH); digitalWrite(led4, LOW); } void LightingPattern4(){ //all lights on digitalWrite(led1, HIGH); digitalWrite(led2, HIGH); digitalWrite(led3, HIGH); digitalWrite(led4, HIGH); }