Hi, I,ve just purchased an arduino duemilanove + motor sheild and started off with my first programming. At first I was a bit confused where to start but now i think I got a bit of a grip on it (I hope) :-/. Anyway I know when I run the programm on arduino, however I was not quite sure how to define the 6 analog pins A0 -A5. Earlier in this post the following was stated:
"the analog 0-5 ADC lines can also be used as GPIO pins. A0-A5 can be accessed as digital 14-19. of course the pin numbers I've used only are valid as long as you use the Arduino specific functions."
Now the below is part of my program where I using pin 14 (A0)as an input from a micro switch and 15 (A1) as an output to an optocoupler to control a relay. From what I understand, these are set as digital by default when refering to them by 14 & 15 and analog when refering to them as A0 and A1, or do I need to declare in the programm that these should be so just the same since they are analog? :-/
#include <AFMotor.h>
AF_Stepper motor2(48,2); //48 stepper motor connected on port 2
AF_Stepper motor1(48,1); //48 stepper motor connected on port 1
#define BUTTON 14; //microswitch connected on pin 14
int val = 0; //Store state of pin 14
#define relay 15; //connected on pin 15
void setup() {
pinMode(14, INPUT); //set pin A0 for microswitch as input
pinMode(15, OUTPUT); //set pin A1 for relay as output
Serial.begin(9600); //setup library at 9600 bps
}
void loop() {{
// Routine to set home position if stepper is not homed
val = digitalRead(14); //read input value from microswitch and store it
if (val = LOW); // when signal from micrswitch is OFF
motor2.setSpeed(100); //Set stepper speed at 100 rpm
motor2.step(100, FORWARD, SINGLE); // Jogs stepper off limit switch incase of overshooting
motor2.step(100, BACKWARD, SINGLE); // returns stepper home until microswitch comes ON
motor2.release(); // Releave power supply on motor
}
char incomingByte;
if (Serial.available() > 0) // Waits for signal from serial (USB port)
incomingByte = Serial.read(); // Reads incoming byte from serial (USB port)
val = digitalRead(7); //read input value from microswitch and store it
if (val = HIGH); //If signal from micrswitch is ON
digitalWrite(15,HIGH); //Switches pin 8 (relay) ON
motor2.setSpeed(40); // Set stepper speed at 40 rpm
motor2.step(100, FORWARD, MICROSTEP); //run stepper forward
motor2.step(100, BACKWARD, MICROSTEP); //run stepper backward home
motor2.release(); // Releave power supply on motor
digitalWrite(15,LOW); //Switches pin 15 (relay) OFF
motor1.setSpeed(40); // Set stepper speed at 40 rpm
motor1.step(100, FORWARD, MICROSTEP); // Run stepper forward
motor1.release(); // Releave power supply on motor
uint8_t cmd[]={0x52}; // TO CHECK IF THIS COMMAND IS VALID
Serial.write(0x52); //HOPEFULLY TO SEND COMMAND TO PROGRAMM ON PC TO START. 0x52 is HEX equivalent of charecter 'R'
}
I not quite sure about the last part about the serial write but so far the programming looks ok when verified with arduino - 0016 .......Hope the same happens when I run it on the setup!! Any comments or recomendation are welcome.
Marten