/* 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 has problems with it that you will need to fix. ◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇ */ /*NAMING SECTION: We name things to keep track of them easily. What will you name your other lights? */ int button1 = 4; int button2 = 19; //Change below to match the pins of your project: int led1 = 3; int led2 = 2; int led3 = 0; int led4 = 1; int led5 = 10; int led6 = 9; int led7 = 6; int led8 = 12; int led9 = 13; /*SETUP SECTION: Put things here that you only need to do once: For instance, OUTPUTS (lights) */ void setup() { // put your setup code here, to run once: pinMode(button1, INPUT); pinMode(button2, INPUT); pinMode(led1, OUTPUT); pinMode(led2, OUTPUT); pinMode(led3, OUTPUT); pinMode(led4, OUTPUT); pinMode(led5, OUTPUT); pinMode(led6, OUTPUT); pinMode(led7, OUTPUT); pinMode(led8, OUTPUT); pinMode(led9, OUTPUT); } /* Debugging Scenario: Agustin wrote the following code for his * Mural Project. He wants to see: * allOn() if both buttons are pushed * blink() if button1 is pushed and button2 is not pushed * blinkFast() if button1 is not pushed and button2 is pushed * allOff() if neither is pushed * Help him debug it. */ /*ACTIVITY SECTION: This is one big loop. Whatever you put in here will run over and over and over again. */ void loop() { // put your main code here, to run repeatedly: int sensorVal1 = digitalRead(button1); int sensorVal2 = digitalRead(button2); //both buttons pushed if(sensorVal1 == HIGH && sensorVal1 == HIGH) { allOn(); } //button1 pushed and button2 not pushed else if(sensorVal1 == HIGH && sensorVal1 == LOW) { blink(); } //button1 not pushed and button2 pushed else if(sensorVal1 == LOW && sensorVal1 == HIGH) { blinkFast(); } //neither button pushed else { allOff(); } } /*BUILDING BLOCKS SECTION: write functions that you can call * when you want */ void allOn() { digitalWrite(led1, HIGH); digitalWrite(led2, HIGH); digitalWrite(led3, HIGH); digitalWrite(led4, HIGH); digitalWrite(led5, HIGH); digitalWrite(led6, HIGH); digitalWrite(led7, HIGH); digitalWrite(led8, HIGH); digitalWrite(led9, HIGH); } void allOff() { digitalWrite(led1, LOW); digitalWrite(led2, LOW); digitalWrite(led3, LOW); digitalWrite(led4, LOW); digitalWrite(led5, LOW); digitalWrite(led6, LOW); digitalWrite(led7, LOW); digitalWrite(led8, LOW); digitalWrite(led9, LOW); } void blink() { allOn(); delay(500); allOff(); delay(500); } void blinkFast() { allOn(); delay(100); allOff(); delay(100); }