Modul Praktik 1 Robotika SMA Marsudirini Bekasi: 1. Mengenal LED
Modul Praktik 1 Robotika SMA Marsudirini Bekasi: 1. Mengenal LED
Modul Praktik 1 Robotika SMA Marsudirini Bekasi: 1. Mengenal LED
1. Mengenal LED
int led1= 2;
void setup(){
pinMode(led1, OUTPUT);
digitalWrite(led1, HIGH);
void loop(){
}
2. LED Paralel
int led1= 2;
void setup(){
pinMode(led1, OUTPUT);
digitalWrite(led1, HIGH);
void loop(){
void setup(){
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(led3, OUTPUT);
digitalWrite(led1, LOW);
digitalWrite(led2, LOW);
digitalWrite(led3, LOW);
}
void loop(){
digitalWrite(led1, HIGH);
delay(1000);
digitalWrite(led1, LOW);
digitalWrite(led2, HIGH);
delay(1000);
digitalWrite(led2, LOW);
digitalWrite(led3, HIGH);
delay(1000);
digitalWrite(led3, LOW);
}
4. Resistor
5. Mengenal Button
int led1= 2;
void setup(){
pinMode(led1, OUTPUT);
digitalWrite(led1, HIGH);
void loop(){
}
6. Button Dengan Algoritma
// C++ code
//
/*
Button
Turns on and off a light emitting diode(LED)
connected to digital pin 13, when pressing a
pushbutton attached to pin 2.
The circuit:
* LED attached from pin 13 to ground
* pushbutton attached to pin 2 from +5V
* 10K resistor attached to pin 2 from ground
* Note: on most Arduinos there is already an LED
on the board attached to pin 13.
int buttonState = 0;
void setup()
{
Serial.begin(9600);
pinMode(2, INPUT);
void loop()
{
// read the state of the pushbutton value
buttonState = digitalRead(2);
if (buttonState == HIGH) {
Serial.println("ON");
} else {
Serial.println("OFF");
}
delay(10); // Delay a little bit to improve simulation performance
}