I am new at programing my Arduino I have made a program that will fade 2 leds 1 from 0 to 255 and the other will fade 5 points every time the first led hit 20. The c program works great but when I make the program with ArduBlock it will not run. Both program look the same other then the way ArduBlock lays it out. I am wondering if it is a waste of time using ArduBlock and just stick with learning c++
Here is a copy of both programs and a screen print of the ArduBlock layout.
Just looking for some input on if the ArduBlock is wrong in some way or if I should stick with the c++ programing.
The c++ program:
/*
Fade
This example shows how to fade an LED on pin 9 and 10
using the analogWrite() function.
This example code is in the public domain.
*/
int led = 9; // the pin that the LED is attached to
int led2 = 10;
int brightness = 0; // how bright the LED is
int bri2 = 0;
int fadeAmount = 5; // how many points to fade the LED by
int fade = 5;
// the setup routine runs once when you press reset:
void setup() {
// declare pin 9 to be an output:
pinMode(led, OUTPUT);
pinMode(led2,OUTPUT);
Serial.begin(9600);
}
// the loop routine runs over and over again forever:
void loop() {
// set the brightness of pin 9 and 10:
analogWrite(led, brightness);
analogWrite(led2,bri2);
//Serial.println(fade);
Serial.println(bri2);
if (brightness == 20){
bri2 = bri2 + fade;
if (bri2 == 0 || bri2 == 255){
fade = -fade ;
}
}
// change the brightness for next time through the loop:
brightness = brightness + fadeAmount;
if (brightness == 0 || brightness == 255) {
fadeAmount = -fadeAmount ;
}
// wait for 30 milliseconds to see the dimming effect
delay(30);
}
The ArduBlock version:
int _ABVAR_1_led = 0 ;
int _ABVAR_2_led2 = 0 ;
int _ABVAR_3_brightness = 0 ;
int _ABVAR_4_bri2 = 0 ;
int _ABVAR_5_fadeamount = 0 ;
int _ABVAR_6_fade = 0 ;
void setup()
{
pinMode( _ABVAR_1_led , OUTPUT);
pinMode( _ABVAR_2_led2 , OUTPUT);
Serial.begin(9600);
_ABVAR_1_led = 9 ;
_ABVAR_2_led2 = 10 ;
_ABVAR_3_brightness = 0 ;
_ABVAR_4_bri2 = 0 ;
_ABVAR_5_fadeamount = 5 ;
_ABVAR_6_fade = 5 ;
}
void loop()
{
analogWrite(_ABVAR_1_led , _ABVAR_3_brightness);
analogWrite(_ABVAR_2_led2 , _ABVAR_4_bri2);
Serial.print(_ABVAR_4_bri2);
Serial.println();
Serial.print(_ABVAR_3_brightness);
Serial.println();
if (( ( _ABVAR_3_brightness ) == ( 20 ) ))
{
_ABVAR_4_bri2 = ( _ABVAR_4_bri2 + _ABVAR_6_fade ) ;
if (( ( ( _ABVAR_4_bri2 ) == ( 0 ) ) || ( ( _ABVAR_4_bri2 ) == ( 255 ) ) ))
{
_ABVAR_6_fade = ( _ABVAR_6_fade - _ABVAR_6_fade ) ;
}
}
_ABVAR_3_brightness = ( _ABVAR_3_brightness + _ABVAR_5_fadeamount ) ;
if (( ( ( _ABVAR_3_brightness ) == ( 0 ) ) || ( ( _ABVAR_3_brightness ) == ( 255 ) ) ))
{
_ABVAR_5_fadeamount = ( _ABVAR_5_fadeamount - _ABVAR_5_fadeamount ) ;
}
delay( 100 );
}