void setup()
{
- pinMode(A1, OUTPUT);
- pinMode(A2, OUTPUT);
- pinMode(EN_L, OUTPUT);
- digitalWrite(A1, LOW);
- digitalWrite(A2, LOW);
- digitalWrite(EN_L, HIGH);
- pinMode(A3, OUTPUT);
- pinMode(A4, OUTPUT);
- pinMode(EN_R, OUTPUT);
- digitalWrite(A3, LOW);
- digitalWrite(A4, LOW);
- digitalWrite(EN_R, HIGH);
+ pinMode(A1, OUTPUT);
+ pinMode(A2, OUTPUT);
+ pinMode(EN_L, OUTPUT);
+ digitalWrite(A1, LOW);
+ digitalWrite(A2, LOW);
+ digitalWrite(EN_L, HIGH);
- aservo.attach(SERVO_PIN);
+ pinMode(A3, OUTPUT);
+ pinMode(A4, OUTPUT);
+ pinMode(EN_R, OUTPUT);
+ digitalWrite(A3, LOW);
+ digitalWrite(A4, LOW);
+ digitalWrite(EN_R, HIGH);
+
+ aservo.attach(SERVO_PIN);
}
void loop()
{
- /*
- digitalWrite(A1, HIGH);
+ /*
+ digitalWrite(A1, HIGH);
analogWrite(A2, 128);
digitalWrite(EN_L, HIGH);
-
- aservo.write(90);
- */
-
+ */
+
+ //aservo.write(90);
+
+ /*
for (uint8_t i = 0; i < 4; i++)
{
forward(255);
}
digitalWrite(EN_L, LOW);
digitalWrite(EN_R, LOW);
+ */
}
void forward(uint8_t speed)
{
- analogWrite(A1, speed);
- digitalWrite(A2, LOW);
- analogWrite(A3, speed);
- digitalWrite(A4, LOW);
+ analogWrite(A1, speed);
+ digitalWrite(A2, LOW);
+ analogWrite(A3, speed);
+ digitalWrite(A4, LOW);
}
void reverse(uint8_t speed)
{
- analogWrite(A2, speed);
- digitalWrite(A1, LOW);
- analogWrite(A4, speed);
- digitalWrite(A3, LOW);
+ digitalWrite(A1, LOW);
+ analogWrite(A2, speed);
+ digitalWrite(A3, LOW);
+ analogWrite(A4, speed);
}
void turn_left(uint8_t speed)
{
- analogWrite(A2, speed);
- digitalWrite(A1, LOW);
- analogWrite(A3, speed);
- digialWrite(A4, LOW);
+ digitalWrite(A1, LOW);
+ analogWrite(A2, speed);
+ analogWrite(A3, speed);
+ digitalWrite(A4, LOW);
}
void turn_right(uint8_t speed)
{
- analogWrite(A1, speed);
- digitalWrite(A2, LOW);
- analogWrite(A4, speed);
- digitalWrite(A3, LOW);
+ analogWrite(A1, speed);
+ digitalWrite(A2, LOW);
+ digitalWrite(A3, LOW);
+ analogWrite(A4, speed);
+}
+
+void stop_motors()
+{
+ digitalWrite(A1, LOW);
+ digitalWrite(A2, LOW);
+ digitalWrite(A3, LOW);
+ digitalWrite(A4, LOW);
}
// Stop reception of interrupts
noInterrupts(); //cli();
- // Set PB1 to be an output (Pin9 Arduino UNO)
+ // Set PB1 to be an output (Pin-9 Arduino UNO)
DDRB |= (1 << PB1);
// Clear Timer/Counter Control Registers
// Set non-inverting mode - Table 15-3 (page 108)
TCCR1A |= (1 << COM1A1);
+ TCCR1A |= (1 << COM1B1);
// Set Fast-PWM Mode (Mode 14) - Table 15-5 (page 109)
TCCR1A |= (1 << WGM11);
// Set PWM frequency/top value - Output PWM 10kHz
ICR1 = 199; // Fclk_io / (Fout * Prescaler) - 1
OCR1A = 100; // Output OC1A will be ON for [OCR1A/(ICR1+1)]% of the time -> 100/(199+1) = 50%
+ OCR1B = 50;
// Enable compare match interrupt
TIMSK1 |= (1 << OCIE1A);
+ TIMSK1 |= (1 << OCIE1B);
TIMSK1 |= (1 << TOIE1);
// Set prescaler to 8 and starts PWM
digitalWrite(13, LOW);
}
+//Timer1 Compare Match Interrupt turns OFF pin 13 (LED)
+ISR(TIMER1_COMPB_vect) {
+ //digitalWrite(13, LOW);
+}
+
//Timer1 Overflow Interrupt turns ON pin 13 (LED)
ISR(TIMER1_OVF_vect) {
digitalWrite(13, HIGH);