0% found this document useful (0 votes)
27 views3 pages

ATX2 Library Guide

The ATX2 Arduino Library Guide provides a custom library for controlling motors, a buzzer, LEDs, and sensors on the ATX2 board, simplifying robot programming. It includes detailed descriptions of library files, functions, and syntax, along with example programs for various functionalities. Users can easily implement motor control, sound, and sensor readings using the provided functions and sample code.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views3 pages

ATX2 Library Guide

The ATX2 Arduino Library Guide provides a custom library for controlling motors, a buzzer, LEDs, and sensors on the ATX2 board, simplifying robot programming. It includes detailed descriptions of library files, functions, and syntax, along with example programs for various functionalities. Users can easily implement motor control, sound, and sensor readings using the provided functions and sample code.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

ATX2 Arduino Library Guide

This guide introduces a custom Arduino library for the ATX2 board. It includes functions for
controlling motors, buzzer, LEDs, and sensors, with sample code for testing. The ATX2 library
simplifies programming robots using the ATX2 board, making it easier to control movement, sound,
and inputs.

Library Files
The library consists of two files: ATX2.h and [Link]. Place them inside a folder named 'ATX2' in
your Arduino libraries folder.

ATX2.h
#ifndef ATX2_H
#define ATX2_H

#include <Arduino.h>

class ATX2 {
public:
ATX2();

void motorLeft(int speed);


void motorRight(int speed);
void motorStop();

void buzzerOn();
void buzzerOff();
void beep(int duration);

void ledOn(uint8_t pin);


void ledOff(uint8_t pin);

int readLineSensor(uint8_t pin);


int readButton(uint8_t pin);
};

#endif

[Link]
#include "ATX2.h"

ATX2::ATX2() {
pinMode(3, OUTPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
}

void ATX2::motorLeft(int speed) {


speed = constrain(speed, -255, 255);
if (speed >= 0) analogWrite(5, speed);
else analogWrite(5, 0);
}

void ATX2::motorRight(int speed) {


speed = constrain(speed, -255, 255);
if (speed >= 0) analogWrite(6, speed);
else analogWrite(6, 0);
}

void ATX2::motorStop() {
analogWrite(5, 0);
analogWrite(6, 0);
}

void ATX2::buzzerOn() { digitalWrite(3, HIGH); }


void ATX2::buzzerOff() { digitalWrite(3, LOW); }

void ATX2::beep(int duration) {


buzzerOn();
delay(duration);
buzzerOff();
}

void ATX2::ledOn(uint8_t pin) {


pinMode(pin, OUTPUT);
digitalWrite(pin, HIGH);
}
void ATX2::ledOff(uint8_t pin) {
pinMode(pin, OUTPUT);
digitalWrite(pin, LOW);
}

int ATX2::readLineSensor(uint8_t pin) {


return analogRead(pin);
}

int ATX2::readButton(uint8_t pin) {


pinMode(pin, INPUT_PULLUP);
return digitalRead(pin);
}

Functions & Syntax


1. Motors - motorLeft(speed): Controls left motor (-255..255) - motorRight(speed): Controls right
motor (-255..255) - motorStop(): Stops both motors 2. Buzzer - buzzerOn(): Turns buzzer ON -
buzzerOff(): Turns buzzer OFF - beep(duration): Beep for duration (ms) 3. LEDs - ledOn(pin):
Turns ON LED at given pin - ledOff(pin): Turns OFF LED at given pin 4. Sensors -
readLineSensor(pin): Reads analog value (0-1023) - readButton(pin): Reads button state (LOW =
pressed)

Example Programs
Example 1: Move Forward then Stop
-------------------------------------
#include <ATX2.h>
ATX2 bot;

void setup() {
[Link](200);
}

void loop() {
[Link](200);
[Link](200);
delay(2000);
[Link]();
[Link](500);
delay(1000);
}
Example 2: Line Sensor Reading
-------------------------------------
#include <ATX2.h>
ATX2 bot;

void setup() {
[Link](9600);
}

void loop() {
int leftValue = [Link](A0);
int rightValue = [Link](A1);
[Link]("Left: ");
[Link](leftValue);
[Link](" Right: ");
[Link](rightValue);
delay(200);
}
Example 3: Button Control
-------------------------------------
#include <ATX2.h>
ATX2 bot;

void setup() {
[Link](9600);
}

void loop() {
if ([Link](2) == LOW) {
[Link](100);
[Link](150);
[Link](150);
} else {
[Link]();
}
}

You might also like