Arduino new-man gogogo!

The first day of learning punch assignments!
I don't know how to sending photos and videos, so I will go to study and discuss with you!
690x388

Do you have a question?

1 Like

Hi, how do you wanna send photos and videos? With Raspberry PI, ESP32 or any other platform?

1 Like

Please don't send videos. It's last resort. It forces people to decide whether they have the time to sit through the whole thing.

1 Like

yes!I have many question.I don't know how to say it. Let me try to describe them.The one is about'Knight-rider'Which is one of my homework.Is like Running back and forth light.The first code I wrote didn't work. I had to go in one direction, not back and forth.

void setup() {
// put your setup code here, to run once:
int i;
for(i=8;i<=13;i++);{
pinMode(i,OUTPUT);
}
}
void loop() {
// put your main code here, to run repeatedly:
F1();
delay(1000);
F2();
delay(1000);

}
void F1()
{
int i;
for(i=8;i<=13;i++);
{
digitalWrite(i,HIGH);
delay(200);
}
for(i=13;i>=8;i--)
{
digitalWrite(i,LOW);
delay(200);
}
}
void F2()
{
int i;
for(i=13;i>=8;i--)
{
digitalWrite(i,HIGH);
delay(200);
}
for(i=8;i<=13;i++);
{
digitalWrite(i,LOW);
delay(200);
}

}

This is my first attempt at programming, which failed. This program doesn't do round-trip repetition, and I don't know what's wrong with it.

Then I went online and found other bloggers' codes, and it worked. But I can't understand one of them. I would really appreciate it if you could give me a solution.

int startPin=8;
int endPin=13;
int j=0;
void setup() {
// put your setup code here, to run once:
for (int i=startPin;i<=endPin;i++){
pinMode(i,OUTPUT);
}
}

void loop() {
// put your main code here, to run repeatedly:
for(int i=startPin;i<=endPin;i++){
digitalWrite(i,LOW);
}
digitalWrite(startPin+j,HIGH);
j=(j+1)%(endPin-startPin+1);
delay(100);
}

I don't quite understand these lines in this set of code:
digitalWrite(startPin+j,HIGH);
j=(j+1)%(endPin-startPin+1);

Thanks for your reply anyway! You're the first person I've met on this site. Nice to meet you!

Use Google translate.

Notice how your code looks like garbage on the screen? It's because you didn't use code tags around the text.

1 Like

I'm sorry that my English is not good enough to understand what you mean.But thank you for your reply!Nice to meet you

https://translate.google.com/

1 Like

I'm sorry! This is the first time I've sent code. Is there any format requirement?

Tust arduino!thank you for your reply.

Yes, it makes it post like this:

void loop() {
// put your main code here, to run repeatedly:
for(int i=startPin;i<=endPin;i++){
digitalWrite(i,LOW);
}
digitalWrite(startPin+j,HIGH);
j=(j+1)%(endPin-startPin+1);
delay(100);
}
1 Like

Wow!it is looks nice. How can I do this?

before_adding_code_tags

1 Like

I got it!Respect!And Thank you!

void setup() {
  // put your setup code here, to run once:
int I;
for(i=8;i<=13;i++);{
  pinMode(i,OUTPUT);
}
}
void loop() {
  // put your main code here, to run repeatedly:
F1();
delay(1000);
F2();
delay(1000);

}
void F1()
{
int I;
  for(i=8;i<=13;i++);
  {
    digitalWrite(i,HIGH);
    delay(200);
  }
  for(i=13;i>=8;i--)
   {
    digitalWrite(i,LOW);
    delay(200);
  }
}
void F2()
{
  int I;
   for(i=13;i>=8;i--)
   {
    digitalWrite(i,HIGH);
    delay(200);
  }
   for(i=8;i<=13;i++);
  {
    digitalWrite(i,LOW);
    delay(200);
  }
 
}

That doesn't compile. C++ is case sensitive so I is not the same as i.

Did you have some question?

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.