Array Exercises with Confirmation

 

  1. Create a sketch entitled Arrays.ino.
  2. Define an array of type byte, with the variable name pins, and populate the array with the values 6, 7, and 8.
  3. Define an array of type byte, with the variable name state, of length 3, but do not populate the array.
  4. Define the int variable, len, and initialize it to the length of the state array, the best way possible.
  5. In the setup() function assign random HIGH or LOW values to each of the cells in the state array. Display the values to the Serial Monitor.
  6. Are the values random? Modify your code so that it is.
Let's bind the pin number with it's initial state more tightly.
  1. Comment out the previous code.
  2. Define the struct pin that encapsulates the pin number with its state.
  3. Define the array pins of base type pin, of length 3.
  4. Hard code the contents of the array to three of the PWM pins and assign a byte value [0,255] to the state field.
  5. Wire your RGBLED to these PWM pins and write code to display the result to confirm.