//CODING 1
/*int LED[5] = {3,10,11,12,13};
int valueanalog = 0;//initilize 0 mula2
void setup()
{
for (int i=1;i<=4;i++)// cara terbaru guna For Loop
{
pinMode (LED[i],OUTPUT);
}
}
void loop()
{
valueanalog = analogRead(A0); //range decimel 0-1023, 10 bit
if(0<valueanalog && valueanalog<300)
{
digitalWrite (LED[1],HIGH);digitalWrite (LED[2],LOW);
digitalWrite (LED[3],LOW);digitalWrite (LED[4],LOW);
}
else if(299<valueanalog && valueanalog<600)
{
digitalWrite (LED[1],LOW);digitalWrite (LED[2],HIGH);
digitalWrite (LED[3],LOW);digitalWrite (LED[4],LOW);
}
else if(599<valueanalog && valueanalog<900)
{
digitalWrite (LED[1],LOW);digitalWrite (LED[2],LOW);
digitalWrite (LED[3],HIGH);digitalWrite (LED[4],LOW);
}
else
{
digitalWrite (LED[1],LOW);digitalWrite (LED[2],LOW);
digitalWrite (LED[3],LOW);digitalWrite (LED[4],HIGH);
}
} */
//==========================================================================================
//CODING 2
/*int LED[5] = {3,10,11,12,13};
int valueanalog = 300; //initilize 0 mula2
int i,y;
void setup()
{
for (int i=1;i<=4;i++)// cara terbaru guna For Loop
{
pinMode (LED[i],OUTPUT);
}
}
void loop()
{
y = analogRead(A0); //sensorValue akan dapat nilai 0-1023,10 bit
for (int i=1;i<=4;i++)// cara terbaru guna For Loop
{
digitalWrite (LED[i],HIGH);
delay(valueanalog);
digitalWrite (LED[i],LOW);
}
}*/
//========================================================================================
//CODING 3
/*#include <LiquidCrystal.h>
// RS E D4 D5 D6 D7
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
int LED[5] = {3,10,11,12,13};
int valueanalog = 0;
void setup()
{ // C R
lcd.begin(16, 2);
lcd.setCursor(0, 0);
lcd.clear();// before anything, clear the LCD
for (int i=1;i<=4;i++)// cara terbaru guna For Loop
{
pinMode (LED[i],OUTPUT);
}
}
void loop()
{
valueanalog = analogRead(A0); //range decimel 0-1023.
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(valueanalog);
delay(500);
//******************
}*/
//========================================================================================
//CODING 4
/*#include <LiquidCrystal.h>
// RS E D4 D5 D6 D7
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
int LED[5] = {3,10,11,12,13};
int valueanalog = 0;
int oldvalue=0;
void setup()
{ // C R
lcd.begin(16, 2);
lcd.setCursor(0, 0);
lcd.clear();// before anything, clear the LCD
for (int i=1;i<=4;i++)// cara terbaru guna For Loop
{
pinMode (LED[i],OUTPUT);
}
}
void loop()
{
valueanalog = analogRead(A0); //range decimel 0-1023.
if(valueanalog!=oldvalue) //TRUE if valueanalog TAK SAMA DGN oldvalue
{
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(valueanalog);
delay(500);
oldvalue = valueanalog; //store the new value
//**************
}
}*/
//========================================================================================
//CODING 5
#include <LiquidCrystal.h>
// RS E D4 D5 D6 D7
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
int LED[5] = {3,10,11,12,13};
int valueanalog = 0;
int oldvalue=0;
float voltage;
void setup()
{ // C R
lcd.begin(16, 2);
lcd.setCursor(0, 0);
lcd.clear();// before anything, clear the LCD
for (int i=1;i<=4;i++)//
{
pinMode (LED[i],OUTPUT);
}
}
void loop()
{
valueanalog = analogRead(A0); //range decimel 0-1023.
// Rescale to potentiometer's voltage (from 0V to 5V):
voltage = floatMap(valueanalog, 0, 1023, 0, 5);
if(voltage!=oldvalue) //TRUE only if there is any changes in value
{
lcd.clear();
lcd.setCursor(0, 0);
String stringOne = "Voltage: ";
String stringTwo = "V";
String stringThree = stringOne + voltage + stringTwo;
lcd.print(stringThree);
delay(500);
oldvalue = voltage; //store the new value
}
}
//function definition baru untuk PROSES data.
// (dataNakProses, dataMinAsal, dataMaxAsal, dataMinBaru, dataMaxBaru)
float floatMap(float x, float in_min, float in_max, float out_min, float
out_max) //process value
{
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}