/* Code by Brian Patton 1/1/2017 Motherboard and 2 IR line follower boards test This example code is in the public domain. */ byte rSensorPin = A0; byte lSensorPin = A1; byte rLED = 21; byte gLED = 22; byte bLED = 23; int rSensorVal; int lSensorVal; //******************************************************** // Setup //******************************************************** // the setup routine runs once when you press reset: void setup() { // put your setup code here, to run once: Serial.begin(9600); //create a Serial port while (!Serial); //wait for the port to open before proceeding delay(500); //wait an extra 1/2 second to be sure pinMode(rLED, OUTPUT); pinMode(gLED, OUTPUT); pinMode(bLED, OUTPUT); } //******************************************************** // Main Loop // the loop routine runs over and over again forever: //******************************************************** void loop() { collectData(); // Call the function to collect the data printData(); // Call the function to print the data graphData(); // Call the function to graph the data glowData(); // Call the function to light 2 LEDs delay(20); } //******************************************************** // Collect the Data //******************************************************** void collectData() { rSensorVal = analogRead(rSensorPin); // Collect the analog data off the pin lSensorVal = analogRead(lSensorPin); // Collect the analog data off the pin } //******************************************************** // Print the Data //******************************************************** void printData() { // Simply print the data Serial.println("Right sensor value = " + (String)rSensorVal); Serial.println("Left sensor value = " + (String)lSensorVal); Serial.println(" "); } //******************************************************** // Graph the Data //******************************************************** void graphData() { //Scale the data by dividing by 15 so it fits in a small serial window for (int i = 0; i <= rSensorVal / 15; i++) { Serial.print("*"); // Print a "*" for every interation of the scaled data } Serial.println(" "); // Create a new line //Scale the data by dividing by 15 so it fits in a small serial window for (int i = 0; i <= lSensorVal / 15; i++) { Serial.print("-"); // Print a "-" for every interation of the scaled data } Serial.println(" "); // Create a new line Serial.println(" "); // Create a new line } //******************************************************** // Make LEDs glow with the Data //******************************************************** void glowData() { // Map the data to fit the analog write range int mapRVal = map(rSensorVal, 0, 1023, 0, 255); int mapLVal = map(lSensorVal, 0, 1023, 0, 255); analogWrite(rLED, mapRVal); //Pulse the LED to dim or brighten the LED analogWrite(gLED, mapLVal); //Pulse the LED to dim or brighten the LED }