////////////////////// Dual Analogue Sensors Part 1 #define sensor A1 #define sensor2 A0 void setup() { // put your setup code here, to run once: Serial.begin(9600); Serial.println("Begins"); //We dont need these anymore because our new function (at the bottom) // takes care of it all for us. // pinMode(sensor, INPUT); // pinMode(sensor2, INPUT); } void loop() { //For analogue Sensors //You can only read 1 analogue value at a time //The Arduino has a switch to share for all the analogue pins // pinMode(sensor, INPUT); Opens the pin // Serial.println(analogRead(sensor)); Gets the value // pinMode(sensor, OUTPUT); Closes the pin so you can do something else later //OR because we have a new function analogueGetValue(port) // we can use that to make things a little easier //Serial.println(analogueGetValue(sensor)); //The extra String's convert the numbers from the function into words so we can make a sentence out of them // See happens when you remove them. Yeah, fun times indeed. // Serial.println(String(analogueGetValue(sensor)) + " " + String(analogueGetValue(sensor2))); if(analogueGetValue(sensor) < 300) Serial.println("LEFT"); else if(analogueGetValue(sensor) > 800) Serial.println("RIGHT"); else Serial.println("CENTER"); delay(1000); } ///////////////////////////////////////////////////////////////////////////// //This is a function, a mini program that returns back the value from //an analogue port. It requires 1 value to work, the port number you want //Example: // // int myJoystickX = analogueGetValue(A4); // //This will get the value at A4 and return it so myJoystickX gets a value int analogueGetValue(int port){ int inputValue; pinMode(port, INPUT); inputValue = analogRead(port); pinMode(port, OUTPUT); return inputValue; }