// (Worksheet 4.5.1 - Pin Maps, Initialization) // (Worksheet 4.5.1 Number 4.) // The const keyword is a variable qualifier that tells the compiler that we don't want this variable's value to change // It is a great way to define things like pins and colors. // Here we define all the i/o pins by name; once, and only once. // const int red1=13; const int red2=12; // Adjust the numbers of the Arduino digital i/o pins to match your group’s schematic. // Add 4 more lines of code to assign pin numbers for the Blue and Green pins. const int row0 = 0; const int row1 = 1; // Add 6 more lines of code to assign pin numbers for the remaining 6 rows. // Add 1 line of code to define a constant for the magneticSensor. // (Worksheet 4.5.1 Number 5.) // Add 3 lines of code to define aliases for red, blue, and green. // These constants help us navigate through the image file // putting the color and row pins in arrays lets us reference them with loop counters // defining a variable outside of the program loops makes it global so every function in this file can reference it. // (Worksheet 4.5.1 Number 6.) // Define a constant array for the 8 row pins. const int rowPin[8] = { row0, row1, //Finish this statement. }; // (Worksheet 4.5.1 Number 7.) // Define an array that contains the first Red, Green, and Blue color pins. int colorPin[3] = { //Add array elements here }; // (Worksheet 4.5.1 Number 7.) // The second row of color pins is necessary because each pin can only drive four LEDs at a time at 10mA each. // Define another array called colorPin2 that contains the second set of Red, Green, and Blue // color pins using the above array as an example. // To turn on an LED, we have to set the Color pin HIGH and the row pin LOW. // Only one Color pin should be on at a time. // To avoid driving the LED backwards we can't drive the row pins HIGH, we have to turn them off by // setting them up as INPUTS // (Worksheet 4.5.1 Number 8.) // Write a function here that will turn all 6 color pins off by using the “digitalWrite” // command and setting the color pins LOW. You have been given the initial function // definition statement and one of the necessary “digitalWrite” statements. // You need to fill in the rest of the statements that the function will // do when it is called. // void clearColorPins(void) { // Turn all color drivers off digitalWrite(red1,LOW); } // Here is a function that will turn OFF only one pair of color pins. // This routine could be used instead of clearColorPins if we are careful to keep track of // which one is on. void clearColorPin(int color) { digitalWrite(colorPin[color],LOW); digitalWrite(colorPin2[color],LOW); } // (Worksheet 4.5.1 Number 9.) // Write a function called setColorPin() that will turn ON one pair of color pins. void setColorPin(int color) { // make sure only one color is on at a time - turn everything off first then turn the one we want on } // (Worksheet 4.5.1 Number 10.) // Setting the pin mode to OUTPUT turns the LED on, setting pin mode to INPUT turns the // LED off. The value should always be LOW. // Write a function called setRowPin(int row) to set (turn on) a row pin. // Write a function called clearRowPin(int row) to clear (turn off) a row pin. (Worksheet 4.5.1 Number 10.) // Everything above this point is a definition. // setup() is where things actually start to run. void setup() { // put your setup code here, to run once: // (Worksheet 4.5.1 Number 11.) // The color pins will be driven HIGH to turn them on, LOW to turn them off // for starters we turn them all off and set them as outputs clearColorPins(); // We have a function to set them all low // Now set the pinModes - I've given you one, do the rest pinMode(red1,OUTPUT); // (Worksheet 4.5.1 Number 11.) // The row pins will always be LOW // We turn them on and off by changing their pinMode // Add code to set the value LOW and pinMode to INPUT for each row pin (Worksheet 4.3.2 Number 11.) digitalWrite(row0,LOW); // need 7 more pinMode(row0,INPUT); // need 7 more: is there an easier way to do this? // (Worksheet 4.5.1 Number 11.) // Write the necessary statements to set the magnetic sensor as an INPUT with a value of HIGH. // (Worksheet 4.5.1 Number 13, 14 & 15.) // Write code here to turn your LED ON and OFF and change its color. // Use the functions we've created in this worksheet. } void loop() { }