#include SoftwareSerial mySerial(0, 1); //TX, RX void setup() { mySerial.begin(9600); } void loop() { delay(1000); //This delay is crucial - it allows the LEDs time to stay lit the correct color setColor(255, 255, 255); // Turn off the LED while sampling // Toggle the pins to input so the Hall Effect sensors can be read pinMode(4, INPUT); pinMode(5, INPUT); pinMode(6, INPUT); // measure magnetic field int raw1 = analogRead(4); // Range : 0..1024 mySerial.println(raw1); //Raw Value = 513 int raw2 = analogRead(5); // Range : 0..1024 mySerial.println(raw2); //Raw Value = 514 int raw3 = analogRead(6); // Range : 0..1024 mySerial.println(raw3); //Raw Value = 510 // Toggle the pins to output so the LED can be lit pinMode(4, OUTPUT); pinMode(5, OUTPUT); pinMode(6, OUTPUT); // Figure out what color to light the LED based on the Hall Effect readings if (raw1 > 473 && raw1 < 553){ if (raw2 > 474 && raw2 < 554){ if (raw3 > 470 && raw3 < 550){ mySerial.write("0"); setColor(0, 0, 0); // White Color } } } if (raw1 > 473 && raw1 < 553){ if (raw2 < 474 || raw2 > 554){ if (raw3 > 470 && raw3 < 550){ mySerial.write("1"); setColor(0, 125, 255); // Yellow Color } } } if (raw1 > 473 && raw1 < 553){ if (raw2 > 474 && raw2 < 554){ if (raw3 < 470 || raw3 > 550){ mySerial.write("2"); setColor(255, 255, 0); // Blue Color } } } if (raw1 < 473 || raw1 > 553){ if (raw2 > 474 && raw2 < 554){ if (raw3 > 470 && raw3 < 550){ mySerial.write("3"); setColor(0, 255, 255); // Red Color } } } if (raw1 > 473 && raw1 < 553){ if (raw2 < 474 || raw2 > 554){ if (raw3 < 470 || raw3 > 550){ mySerial.write("4"); setColor(255, 0, 255); // Green Color } } } if (raw1 < 473 || raw1 > 553){ if (raw2 < 474 || raw2 > 554){ if (raw3 > 470 && raw3 < 550){ mySerial.write("5"); setColor(5, 215, 255); // Orange Color } } } if (raw1 < 473 || raw1 > 553){ if (raw2 > 474 && raw2 < 554){ if (raw3 < 470 || raw3 > 550){ mySerial.write("6"); setColor(25, 247, 142); // Purple Color } } } if (raw1 < 473 || raw1 > 553){ if (raw2 < 474 || raw2 > 554){ if (raw3 < 470 || raw3 > 550){ mySerial.write("7"); setColor(255, 255, 255); // Turn off the LED when all 3 blocks are in place - I would have preferred to light brown, but I can't figure out how to make an LED show that color } } } } void setColor(int redValue, int greenValue, int blueValue) { analogWrite(4, redValue); analogWrite(5, greenValue); analogWrite(6, blueValue); }