Sarah Worthington
Created April 2, 2018

Interactive Map

Press a button on the country to see the current time, flag,

3

Things used in this project

Hardware components

Rotary potentiometer (generic)
Rotary potentiometer (generic)
×1
LED (generic)
LED (generic)
×1

Story

Read more

Code

Code

Java
///////////CONTROL 1 LED//////////////////////////////////////

const int buttonPin = 2;     // the number of the pushbutton pin
const int ledPin =  13;      // the number of the LED pin
const int ledPin2 =  12;
const int ledPin3 =  11;

const int analogPin = A1;
int inputValue = 0;
int outputValue = 0;

int buttonState = 0;         // variable for reading the pushbutton status
int ledState = 0; 
int ledState2 = 0; 
int ledState3 = 0; 

void setup() 
{
  pinMode(ledPin, OUTPUT);
  pinMode(ledPin2, OUTPUT);
  pinMode(ledPin3, OUTPUT);
  pinMode(buttonPin, INPUT);
}

void loop() 
{ 
  
inputValue = analogRead(analogPin);//read the value from the sensor
outputValue = map(inputValue,0,1023,0,255);//Convert from 0-1023 proportional to the number of a number of from 0 to 255
 
  buttonState = digitalRead(buttonPin);
  ledState = digitalRead(ledPin);
  ledState2 = digitalRead(ledPin2);
  ledState3 = digitalRead(ledPin3);
 
 if (outputValue < 80) 
  {
  ///////////////////////////
  if (buttonState == HIGH) 
  {
    
    if (ledState == HIGH) 
    {
   		 digitalWrite(ledPin, LOW);
    }
    if (ledState == LOW)
    {
    	digitalWrite(ledPin, HIGH);
    }
    
  }
  ///////////////////////////
 }
  else if (outputValue < 160) 
  {
   ///////////////////////////
  if (buttonState == HIGH) 
  {
    
    if (ledState2 == HIGH) 
    {
   		 digitalWrite(ledPin2, LOW);
    }
    if (ledState2 == LOW)
    {
    	digitalWrite(ledPin2, HIGH);
    }
    
  }
  ///////////////////////////
  }
 else if (outputValue <= 255) 
  {
   ///////////////////////////
  if (buttonState == HIGH) 
  {
    
    if (ledState3 == HIGH) 
    {
   		 digitalWrite(ledPin3, LOW);
    }
    if (ledState3 == LOW)
    {
    	digitalWrite(ledPin3, HIGH);
    }
    
  }
  ///////////////////////////
 
}
  delay(200);
}

Credits

Sarah Worthington

Sarah Worthington

2 projects • 2 followers
Contact

Comments