0% found this document useful (0 votes)
5 views3 pages

Ankt

The document is an Arduino sketch that defines pins for six LEDs and six analog inputs. It initializes the LED pins as outputs and the analog pins as inputs in the setup function. In the loop function, it reads the values from the analog inputs and adjusts the brightness of the corresponding LEDs based on the readings, turning them on at full brightness when the input is low and dimming them after one second.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views3 pages

Ankt

The document is an Arduino sketch that defines pins for six LEDs and six analog inputs. It initializes the LED pins as outputs and the analog pins as inputs in the setup function. In the loop function, it reads the values from the analog inputs and adjusts the brightness of the corresponding LEDs based on the readings, turning them on at full brightness when the input is low and dimming them after one second.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

/* Define the pins for the LEDs //1s

const int ledPin1 = 3; //1l s2


const int ledPin2 = 5; //l2 s3
const int ledPin3 = 6; //l3 s4
const int ledPin4 = 9; //l4 s5
const int ledPin5 = 10; //l5 s6
const int ledPin6 = 11; //l6

*/

// Define the pins for the LEDs

const int ledPin1 = 3;


const int ledPin2 = 5;
const int ledPin3 = 6;
const int ledPin4 = 9;
const int ledPin5 = 10;
const int ledPin6 = 11;

// Define the pins for the analog inputs


const int analogPin1 = A0;
const int analogPin2 = A1;
const int analogPin3 = A2;
const int analogPin4 = A3;
const int analogPin5 = A4;
const int analogPin6 = A5;

// Variable to store the time when the LED brightness was last changed
unsigned long previousMillis1 = 0;
unsigned long previousMillis2 = 0;
unsigned long previousMillis3 = 0;
unsigned long previousMillis4 = 0;
unsigned long previousMillis5 = 0;
unsigned long previousMillis6 = 0;

void setup() {
// Initialize the LED pins as outputs
Serial.begin(9600);
pinMode(ledPin1, OUTPUT);
pinMode(ledPin2, OUTPUT);
pinMode(ledPin3, OUTPUT);
pinMode(ledPin4, OUTPUT);
pinMode(ledPin5, OUTPUT);
pinMode(ledPin6, OUTPUT);

// Initialize the analog input pins as inputs


pinMode(analogPin1, INPUT);
pinMode(analogPin2, INPUT);
pinMode(analogPin3, INPUT);
pinMode(analogPin4, INPUT);
pinMode(analogPin5, INPUT);
pinMode(analogPin6, INPUT);
}

void loop() {
// Read the digital values from the analog input pins
int value1 = digitalRead(analogPin1);
int value2 = digitalRead(analogPin2);
int value3 = digitalRead(analogPin3);
int value4 = digitalRead(analogPin4);
int value5 = digitalRead(analogPin5);
int value6 = digitalRead(analogPin6);

// Set the brightness of the LEDs based on the sensor readings


if (value1 == 0) {
analogWrite(ledPin1, 255);
previousMillis1 = millis();
} else {
if (millis() - previousMillis1 >= 1000) {
analogWrite(ledPin1, 30);
}
}

if (value2 == 0) {
analogWrite(ledPin2, 255);
previousMillis2 = millis();
} else {
if (millis() - previousMillis2 >= 1000) {
analogWrite(ledPin2, 30);
}
}

if (value3 == 0) {
analogWrite(ledPin3, 255);
previousMillis3 = millis();
} else {
if (millis() - previousMillis3 >= 1000) {
analogWrite(ledPin3, 30);
}
}

if (value4 == 0) {
analogWrite(ledPin4, 255);
previousMillis4 = millis();
} else {
if (millis() - previousMillis4 >= 1000) {
analogWrite(ledPin4, 30);
}
}

if (value5 == 0) {
analogWrite(ledPin5, 255);
previousMillis5 = millis();
} else {
if (millis() - previousMillis5 >= 1000) {
analogWrite(ledPin5, 30);
}
}

if (value6 == 0) {
analogWrite(ledPin6, 255);
previousMillis6 = millis();
} else {
if (millis() - previousMillis6 >= 1000) {
analogWrite(ledPin6, 30);
}
}

You might also like