0% found this document useful (0 votes)
9 views

Arduino

The document discusses using the Arduino framework to control the movement of a robot using functions and the millis() timer function without delay() to move the robot forward, backward, stop, turn left and turn right at different time intervals.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

Arduino

The document discusses using the Arduino framework to control the movement of a robot using functions and the millis() timer function without delay() to move the robot forward, backward, stop, turn left and turn right at different time intervals.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

Arduino

Framework
Cth pergerakan turnleft
Penggunaan function millis () tanpa delay ()

1000 = 1 saat (TIMER)

Int – data type - interger

Unsigned long (no +ve)


void setup() {

// put your setup code here, to run once:

// pin2 output

pinMode (2, OUTPUT);

// pin3 output

// pin4 output

// pin5 output

// pin6 output

// pin7 output

pinMode (3, OUTPUT);

pinMode (4, OUTPUT);

pinMode (5, OUTPUT);

void loop() {

// put your main code here, to run repeatedly:

unsigned long current_time = millis();

unsigned long previous_time;

if ((current_time - previous_time) <= 1000) {

forword();

else if ((current_time - previous_time) <= 1000) {

stop();

else if ((current_time - previous_time) <= 300) {

turnright();

else if ((current_time - previous_time) <= 1000) {

stop();

}
void forword (void)

digitalWrite (4, HIGH);

digitalWrite (5, LOW);

digitalWrite (2, LOW);

digitalWrite (3, HIGH);

void backword (void)

digitalWrite (4, LOW);

digitalWrite (5, HIGH);

digitalWrite (2, HIGH);

digitalWrite (3, LOW);

void stop (void)

digitalWrite (4, LOW);

digitalWrite (5, LOW);

digitalWrite (2, LOW);

digitalWrite (3, LOW);

void turnleft (void)

digitalWrite (4, LOW);

digitalWrite (5, HIGH);

digitalWrite (2, LOW);

digitalWrite (3, HIGH);

void turnright (void)

{
digitalWrite (4, HIGH);

digitalWrite (5, LOW);

digitalWrite (2, HIGH);

digitalWrite (3, LOW);

You might also like