3 Replies Latest reply on Apr 23, 2019 8:11 AM by dzuz

    Arduno Code to C/C++ for LED Cube

    dzuz

      Does anyone know how to convert arduino code to c/c++?

       

      I have made a 4x4x4 LED cube, but I need to have the code in c/c++, not just arduino code.

       

      If anyone knows of a converter or can link a site to easily learn c/c++ on an arduino, that would be greatly appreciated. Thanks!

       

      -Dan

        • Re: Arduno Code to C/C++ for LED Cube
          fmilburn

          Hi Daniel,

           

          Arduino code is C++ in an IDE with pin mapping and standard access to timers and other hardware features regardless of the microcontroller.  There are also numerous libraries providing access to sensors, LEDs, motors and such. 

           

          So there is no conversion to C++ since it is already C++.  But it will be necessary to do all of the underlying register setting and library writing that an Arduino already provides.  In other words you will need to learn to implement basic C++ on a microcontroller - without this you will be lost.  It would be difficult to comment further without knowing the microcontroller you are using but my recommendation is to select one with good tutorials for getting started. You will need to learn how to use timers and set and change a gpio pin as a start. 

           

          Frank

          3 of 3 people found this helpful
          • Re: Arduno Code to C/C++ for LED Cube
            dzuz

            I was instructed to change the code below into C or C++. I have to do it with out using digitalwrite. I tried something, to turn all LEDs (turnEverythingOn();) on with the code all the way at the bottom (bolded). Is anyone able to confirm that my code would work?

             

            //initializing and declaring led rows

              int column[18]={13,12,11,10,9,8,7,6,5,4,3,2,1,0,A5,A4};

            //initializing and declaring led layers

              int layer[4]={A3,A2,A1,A0};

             

             

              int time = 250;

             

            void setup()

            {

              //setting rows to ouput

              for(int i = 0; i<16; i++)

              {

                pinMode(column[i], OUTPUT);

              }

              //setting layers to output

              for(int i = 0; i<4; i++)

              {

                pinMode(layer[i], OUTPUT);

              }

              //seeding random for random pattern

              randomSeed(analogRead(10));

            }

            //xxxxxxxxxxxxxxxxxxxxFUNCTION LOOPxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

            //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

             

             

            void loop()

            {

              turnEverythingOff();//turn all off

              flickerOn();

              turnEverythingOn();//turn all on

            }

             

            void turnEverythingOff()

            {

               for(int i = 0; i<16; i++)

               {

                 digitalWrite(column[i], 1);

               }

               for(int i = 0; i<4; i++)

               {

                 digitalWrite(layer[i], 0);

               }

            }

             

            ////////////////////////////////////////////////////////////turn all on

            void turnEverythingOn()

            {

              for(int i = 0; i<16; i++)

              {

                digitalWrite(column[i], 0);

              }

              //turning on layers

              for(int i = 0; i<4; i++)

              {

                digitalWrite(layer[i], 1);

              }

            }

            ///////////////////////////////////////////////////////turn columns off

            void turnColumnsOff()

            {

              for(int i = 0; i<16; i++)

              {

                digitalWrite(column[i], 1);

              }

            }

            /////////////////////////////////////////////////////////////flicker on

            void flickerOn()

            {

              int i = 150;

              while(i != 0)

              {

                turnEverythingOn();

                delay(i);

                turnEverythingOff();

                delay(i);

                i-= 5;

              }

            }

             

            void loop()

            {

            turnEverythingOn();
            }

            void turnEverythingOn()

            {

            DDRD = 0xFF; //setting outputs
            DDRC = 0x3F;
            DDRB = 0xC3;

            PORTD = 0xFF; //PD0-PD7 8pins
            PORTB.0 = 0xFF; //PB0 & PB1 2pins
            PORTB.1 = 0xFF;
            PORTC.0 = 0xFF; //PC0-PC5 6pins
            PORTC.1 = 0xFF;
            PORTC.2 = 0xFF;
            PORTC.3 = 0xFF;
            PORTC.4 = 0xFF;
            PORTC.5 = 0xFF;

            }

            • Re: Arduno Code to C/C++ for LED Cube
              dzuz

              I try to compile the code and I keep getting this error. Does anyone know how I could resolve this issue?

              Thanks!