Names: Period: Date: E-Textiles 1A Assignment 7B –- Sensor as Analog Input - Storyboard

Objectives: In this activity you will: ● Use a switch as input ● Program their own computational circuit using conditionals ● Write functions to organize and reuse code.

To turn in your completed answer document: 1. Named your document #-ECS-Asign8B–Storyboard-Last,First where # is your period. 2. Upload your file to Mr. Gonzalez Textiles’ DropItTo.me (https://dropitto.me/MrGonzalezTextiles ) 3. Use the password etextiles

Sensor as Analog Input – Storyboard Let’s get 0 to 5 lights to light up depending on the brightness.

NAMING SECTION: 1. Based on the variables declared in this section (see below),

int lightSensor = A5; int brightness = 0;

a. Which component on the Circuit Playground do you think is the light sensor?

2. Which variable above do you think we will use to hold the value from the light sensor?

SETUP SECTION: 3. Type in the line below that sets the variable “lightSensor” to INPUT

void setup(){ CircuitPlayground.begin(); pinMode(lightSensor, INPUT); Serial.begin(9600); }

4. Download and Open Light_Sensor_Starter.ino from the website. Experiment with the light sensor.

a. What’s the biggest number you can get?

b. What’s the smallest number you can get?

Fill in the blanks below to define ranges of numbers for each light pattern:

 brightness is greater than or equal to 10 lights turn on

 brightness is greater than or equal to and less than 8 lights turn on

 brightness is greater than or equal to and less than 6 lights turn on

 brightness is greater than or equal to and less than 4 lights turn on

 brightness is greater than or equal to and less than 2 light turns on

 brightness is less than or equal to 0 lights turn on BUILDING BLOCKS SECTION: In this section there are already functions defined for you: Function: Behavior: light0(); 0 lights on light2(); 2 lights on light4(); 4 lights on light6(); 6 lights on light8(); 8 lights on light10(); 10 lights on

ACTIVITY SECTION: 5. Complete the loop() function to call the functions from the BUILDING BLOCKS SECTION above for the conditions you specified in #4. Comparison Operators x == y (x is equal to y) x != y (x is not equal to y) x < y (x is less than y) x > y (x is greater than y) x <= y (x is less than or equal to y) x >= y (x is greater than or equal to y)

void loop() { // read the value from the sensor:

brightness = analogRead(lightSensor); Serial.println(brightness); delay(100);

//your code goes here: There are going to be 6 six conditionals. (six if’s) Example: if(brightness >= 123) { pattern }

}

6. Copy your code into your Arduino program, test, and debug.

7. In your own words, describe how your program chooses which light pattern function to call in the loop() function: