Hello,
I have recently run into an issue when trying to run the sketch that i used on my Arduino Uno on the A-Star Micro, on my Arduino the code runs perfectly and does what is intended but when trying to run it on the A-Star it doesn’t power the correct pins if any at all, etc. I assume that the A-Star has a different way of defining the pins but i am not sure, here is my code:
[code]const int pingPin = 7;
const int outputPin = 12;
const int readyLedPin = 11;
const int calLedPin = 10;
int sensorValue = 0;
int sensorMax = 0;
void setup() {
pinMode(calLedPin, OUTPUT);
digitalWrite(calLedPin, HIGH);
while(millis() < 5000){
pinMode(pingPin, OUTPUT);
digitalWrite(pingPin, LOW);
delayMicroseconds(2);
digitalWrite(pingPin, HIGH);
delayMicroseconds(5);
digitalWrite(pingPin, LOW);
pinMode(pingPin, INPUT);
sensorValue = pulseIn(pingPin, HIGH);
if (sensorValue > sensorMax) {
sensorMax = sensorValue - 100;
}
}
digitalWrite(calLedPin, LOW);
Serial.begin(9600);
digitalWrite(readyLedPin, HIGH);
}
void loop(){
long duration, cm;
pinMode(pingPin, OUTPUT);
digitalWrite(pingPin, LOW);
delayMicroseconds(2);
digitalWrite(pingPin, HIGH);
delayMicroseconds(5);
digitalWrite(pingPin, LOW);
pinMode(pingPin, INPUT);
duration = pulseIn(pingPin, HIGH);
cm = microsecondsToCentimeters(duration);
Serial.print(cm);
Serial.print(“cm”);
Serial.println();
delay(100);
if (duration < sensorMax)
{
digitalWrite(outputPin, HIGH);
delay (5000);
digitalWrite(outputPin, LOW);
}
}
long microsecondsToCentimeters(long microseconds)
{
return microseconds / 29 / 2;
}[/code]
Help would be appreciated, Thanks.