0% found this document useful (0 votes)
59 views2 pages

Nama: Siti Rohmatul Jannah NIM: P27838117002 Kelas: 2B Tugas Teori Mikro 6 Desember 2018

This document contains an Arduino code written by Siti Rohmatul Jannah for a microcontroller assignment. The code uses serial communication to control 3 LEDs on pins 16, 17, and 18 based on characters received - 'a' runs the LEDs in sequence, 'b' toggles all LEDs on and off, and 'c' turns all LEDs off. It sets the pin modes in setup() and checks for serial input in loop(), setting a data variable and running the corresponding LED routine.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
59 views2 pages

Nama: Siti Rohmatul Jannah NIM: P27838117002 Kelas: 2B Tugas Teori Mikro 6 Desember 2018

This document contains an Arduino code written by Siti Rohmatul Jannah for a microcontroller assignment. The code uses serial communication to control 3 LEDs on pins 16, 17, and 18 based on characters received - 'a' runs the LEDs in sequence, 'b' toggles all LEDs on and off, and 'c' turns all LEDs off. It sets the pin modes in setup() and checks for serial input in loop(), setting a data variable and running the corresponding LED routine.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Nama : SITI ROHMATUL JANNAH

NIM : P27838117002
Kelas : 2B
TUGAS TEORI MIKRO 6 DESEMBER 2018

int bacadata;
int data;

void setup() {
// put your setup code here, to run once:
pinMode(16,OUTPUT);
pinMode(17,OUTPUT);
pinMode(18,OUTPUT);
Serial.begin(9600);
}

void loop() {
// put your main code here, to run repeatedly:
{
if(Serial.available())
{
bacadata=Serial.read();
if(bacadata=='a'){data=1;}
if(bacadata=='b'){data=2;}
if(bacadata=='c'){data=3;}

if(data=1) // LED Running


Run:
{
digitalWrite(16,HIGH);
delay(1000);
digitalWrite(16,LOW);
delay(1000);
digitalWrite(17,HIGH);
delay(1000);
digitalWrite(17,LOW);
delay(1000);
digitalWrite(18,HIGH);
delay(1000);
digitalWrite(18,LOW);
delay(1000);
Serial.println("LED RUNNING");
loop();
goto Run;
}

if(data=2) // LED Flip Flop


FF:
{
digitalWrite(16,HIGH);
digitalWrite(17,HIGH);
digitalWrite(18,HIGH);
delay(1000);
digitalWrite(16,LOW);
digitalWrite(17,LOW);
digitalWrite(18,LOW);
delay(1000);
Serial.println("LED FlipFlop");
loop();
goto FF;
}

if(data=3) // LED OFF


OFF:
{
digitalWrite(16,LOW);
digitalWrite(17,LOW);
digitalWrite(18,LOW);
delay(1000);
Serial.println("LED OFF");
loop();
goto OFF;
}
}}}

You might also like