- TS TS
- #21
Attachments
-
You do not have permission to view the full content of this post. Log in or register now.
Ahh.. cge2 ...sensya na lods pero iba yung output sa ginagawa ko salamat sa help!
ito po yung exercise na gagawin namin
View attachment 2614334
Ano course mo lods?sensya na lods pero iba yung output sa ginagawa ko salamat sa help!
ito po yung exercise na gagawin namin
View attachment 2614334
Electrical engineering lods pero may parang minor subject kami microprocessor which is mag program at laki din pakinabang nito sa thesis kaya nag practice2 ako ang mahal ng bayad mag pa programAno course mo lods?
arduino code for led pin 0 to 13, 1 led at a time running from both endsSure, here's an example code for 14 LEDs connected to digital pins 0 to 13 on an Arduino Uno, moving in opposite directions:
Code:C++ void setup() { for (int i = 0; i <= 13; i++) { pinMode(i, OUTPUT); // set the digital pins to OUTPUT mode } } void loop() { for (int i = 0; i <= 6; i++) { digitalWrite(i, HIGH); // turn on LEDs from pin 0 to 6 digitalWrite(13 - i, HIGH); // turn on LEDs from pin 13 to 7 delay(100); // wait for 100ms digitalWrite(i, LOW); // turn off LEDs from pin 0 to 6 digitalWrite(13 - i, LOW); // turn off LEDs from pin 13 to 7 } for (int i = 6; i >= 0; i--) { digitalWrite(i, HIGH); // turn on LEDs from pin 0 to 6 digitalWrite(13 - i, HIGH); // turn on LEDs from pin 13 to 7 delay(100); // wait for 100ms digitalWrite(i, LOW); // turn off LEDs from pin 0 to 6 digitalWrite(13 - i, LOW); // turn off LEDs from pin 13 to 7 } }
This code uses two for loops to move the LEDs in opposite directions. The first for loop turns on the LEDs from pin 0 to 6 and from pin 13 to 7, and then turns them off in reverse order. The second for loop does the same thing, but in reverse order. The delay(100) statement is used to pause for 100 milliseconds between each movement. You can adjust the delay time to change the speed of the LED movement.
int ledPin = 0; // start at pin 0
int direction = 1; // start moving to the right
void setup() {
// initialize all LED pins as outputs
for (int i = 0; i <= 13; i++) {
pinMode(i, OUTPUT);
}
}
void loop() {
// turn off previous LED
digitalWrite(ledPin - direction, LOW);
// turn on current LED
digitalWrite(ledPin, HIGH);
// move to next LED
ledPin += direction;
// change direction if we've reached the end
if (ledPin == 13 || ledPin == 0) {
direction *= -1;
}
// add a delay to control the speed of the animation
delay(100);
}
ledPin
to keep track of which LED we're currently illuminating. We start at pin 0 and move in the direction
of 1 (to the right). We use a for loop in the setup()
function to initialize all LED pins as outputs.loop()
function, we turn off the previous LED by setting its pin to LOW. We then turn on the current LED by setting its pin to HIGH. We then move to the next LED by incrementing or decrementing the ledPin
variable, depending on the direction
we're moving. If we've reached the end of the LED strip (pin 13 or pin 0), we change the direction
so that we start moving in the opposite direction.arduino code for led pin 0 to 13, led both ends running at a time running from both ends accross to other endSure, I can help you with that! Here's the code that will run LEDs from pins 0 to 13, one LED at a time running from both ends:
Code:int ledPin = 0; // start at pin 0 int direction = 1; // start moving to the right void setup() { // initialize all LED pins as outputs for (int i = 0; i <= 13; i++) { pinMode(i, OUTPUT); } } void loop() { // turn off previous LED digitalWrite(ledPin - direction, LOW); // turn on current LED digitalWrite(ledPin, HIGH); // move to next LED ledPin += direction; // change direction if we've reached the end if (ledPin == 13 || ledPin == 0) { direction *= -1; } // add a delay to control the speed of the animation delay(100); }
This code uses a variable calledledPin
to keep track of which LED we're currently illuminating. We start at pin 0 and move in thedirection
of 1 (to the right). We use a for loop in thesetup()
function to initialize all LED pins as outputs.
In theloop()
function, we turn off the previous LED by setting its pin to LOW. We then turn on the current LED by setting its pin to HIGH. We then move to the next LED by incrementing or decrementing theledPin
variable, depending on thedirection
we're moving. If we've reached the end of the LED strip (pin 13 or pin 0), we change thedirection
so that we start moving in the opposite direction.
Finally, we add a delay to control the speed of the animation. You can adjust the delay time to speed up or slow down the animation as desired.
Here's the code that will run LEDs from pins 0 to 13, with two LEDs moving towards each other from both ends and meeting in the middle:arduino code for led pin 0 to 13, led both ends running at a time running from both ends accross to other end
int ledPinLeft = 0;
int ledPinRight = 12;
int directionLeft = 1;
int directionRight = -1;
void setup() {
for (int i = 0; i <= 13; i++) {
pinMode(i, OUTPUT);
}
}
void loop() {
digitalWrite(ledPinLeft, HIGH);
digitalWrite(ledPinRight, HIGH);
ledPinLeft += directionLeft;
ledPinRight += directionRight;
if (ledPinLeft == ledPinRight) {
delay(500);
} else {
delay(100);
}
if (ledPinLeft == 13 || ledPinLeft == 0) {
directionLeft *= -1;
}
if (ledPinRight == 13 || ledPinRight == 0) {
directionRight *= -1;
}
digitalWrite(ledPinLeft - directionLeft, LOW);
digitalWrite(ledPinRight - directionRight, LOW);
}
ledPinLeft
and ledPinRight
, to keep track of the LED pins on the left and right sides of the strip, respectively. We start at pins 0 and 12, and move in opposite directions (directionLeft = 1
and directionRight = -1
). The setup()
function initializes all pins as outputs.loop()
function, we turn on both LEDs on each iteration, and then move the LED pins by incrementing or decrementing the ledPinLeft
and ledPinRight
variables. We then use a delay to control the speed of the animation. When the two LED pins meet in the middle, we add an extra delay of 500ms before continuing the animation.LOW
.delay()
function and the directionLeft
and directionRight
variables, respectively.