Arduino project handbook variable question in a program

Hi everyone. I have tried to find an answer to this before asking for help. I’m new to programming but I am slowly getting the hang of it. The question I have about the following code is, the first line in the void loop.
I see , pos=0 I;
I see where durations and distance is used but not the rest .
If duration, distance and pos are =0, what is I? What is pos variable for?
Thank you all for helping newcomers like me!
#include <NewPing.h> // This calls the NewPing library
#include <Servo.h> // Calls the Servo library
#define trigPin 12 // Trig pin attached to Arduino 12
#define echoPin 13 // Echo pin attached to Arduino 13
#define MAX_DISTANCE 500

NewPing sonar(trigPin, echoPin, MAX_DISTANCE);

int greenLed = 3, redLed = 2; // Green LED to 3, Red to 2

int pos = 20;
Servo myservo;

void setup() {
Serial.begin (115200);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(greenLed, OUTPUT);
pinMode(redLed, OUTPUT);
myservo.attach(9); // Servo attached to pin 9

void loop() {
int duration, distance,pos=0,i;

digitalWrite(trigPin, LOW);
digitalWrite(trigPin, HIGH); // Trig sends a ping
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH); // Echo receives the ping
distance = (duration/2) / 29.1;
Serial.println(" cm");

if(distance<=15) // If distance is less than 15
digitalWrite(greenLed, LOW); // Green LED goes off
digitalWrite(redLed, HIGH); // Red LED on
myservo.write(180); // Move servo
digitalWrite(redLed, LOW);
digitalWrite(redLed, HIGH);
digitalWrite(redLed, LOW);
else{ // Otherwise do this
digitalWrite(redLed, LOW); // Red LED off
digitalWrite(greenLed, HIGH); // Green LED on


It's a bit odd to have two variables called pos in scope

Also. I assume pos is position, but I don't see how it's tied to the servo.


The variables "pos" and "i" are never used. Leave them out.


Thanks! I thought that they were not used at first but didn’t trust myself, because he used the same line in another project. Whooo my mind can rest now.