void setup() {
// initialize digital pin 13 as an output.
pinMode(13, OUTPUT);
}
// the loop function runs over and over again forever
void loop() {
digitalWrite(13, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(13, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}
Look at your first code. Where do you set pin 13 as an OUTPUT? You DO set the pin number in the variable _ABVAR_1_pin13 to an OUTPUT, but, in spite of the name, the VALUE in the variable is NOT 13.
You should ALWAYS use const for pin number variable, so you can't do this:
_ABVAR_1_pin13 = 13 ;
Setting the value in the variable AFTER you have used the variable in the pinMode() call is wrong.
According the kind to define the output ( directly or using a int varaible), the voltage is not the same
Example:
Work correctly
void setup() {
pinMode(13, OUTPUT);
}
void loop() {
digitalWrite(13, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(13, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}
Do not work correctly: pin 13 = 1.6vmax and the led doaes not light
KeithRB:
You need to set _ABVAR_1_pin13 to 13 in set up to set the correct pin to an OUTPUT.
Thanks for this information. But... In fact i m a teacher for young people and this "c code is produce" using a plugin 'Ardublock' for arduino. (A kind of graphical coding ).
Sure, it s not the kind of code i would write in C, but It should work, as there is no real error.
the int variable is initialized as 0 before the setup
the pin is set in the setup as output usin the int_variable
the pin is set in the loop as 13.
In fact, i discovered this strange behavior of the arduino bd due to the poor amout of light from the led.
It works, but, we need to use transistors to light the led !!. ( only 1.6 v on output.
here is example of graphical programme from ardublock.
davidnewone:
Here is the issue:
Not possible with digitalWrite(_ABVAR_1_pin13 , HIGH);
OK with analogWrite(_ABVAR_1_pin13 , HIGH);
Nevertheless, i do not undertand why !! According th the specifications, it should work using digitalwrite instruction !
Can't check at this moment but from memory analogWrite calls the pinMode function to set the pin to output before writing to the output and that is why it works.