?
Solved

Convert C++ to acceptable Arduino C++

Posted on 2014-09-08
1
Medium Priority
?
127 Views
Last Modified: 2014-12-27
I have the following working C++ code in GCC and want to convert it to its Arduino C++ compatible version to produce the output listed just below this code:

#include <vector>
#include <iostream>
#include <algorithm>

void fadeOn(int maxvalue, int maxlength) {
    int counter;
    int maxcounter = 1;
    int vtemp = 0;
    
    std::vector<int> v{1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; 
    
    for (counter=1; counter < maxlength + maxvalue; counter++) {
      // simple rotation to the right
      
      std::cout << "simple rotate right " << counter << ": ";
      for (int n: v)
          std::cout << n << ' ';
      std::cout << '\n';
      
      vtemp = v[0];
      
      std::rotate(v.rbegin(), v.rbegin() + 1, v.rend());
      
      if (maxcounter < maxvalue) {
        v[0] = vtemp + 1;
      } else {
        v[0] = maxvalue;
      }
      
      maxcounter++;
    }
}

int main()
{
    fadeOn(7,13);
}

Open in new window


CURRENT OUTPUT of above code:

simple rotate right 1: 1 0 0 0 0 0 0 0 0 0 0 0 0
simple rotate right 2: 2 1 0 0 0 0 0 0 0 0 0 0 0
simple rotate right 3: 3 2 1 0 0 0 0 0 0 0 0 0 0
simple rotate right 4: 4 3 2 1 0 0 0 0 0 0 0 0 0
simple rotate right 5: 5 4 3 2 1 0 0 0 0 0 0 0 0
simple rotate right 6: 6 5 4 3 2 1 0 0 0 0 0 0 0
simple rotate right 7: 7 6 5 4 3 2 1 0 0 0 0 0 0
simple rotate right 8: 7 7 6 5 4 3 2 1 0 0 0 0 0
simple rotate right 9: 7 7 7 6 5 4 3 2 1 0 0 0 0
simple rotate right 10: 7 7 7 7 6 5 4 3 2 1 0 0 0
simple rotate right 11: 7 7 7 7 7 6 5 4 3 2 1 0 0
simple rotate right 12: 7 7 7 7 7 7 6 5 4 3 2 1 0
simple rotate right 13: 7 7 7 7 7 7 7 6 5 4 3 2 1
simple rotate right 14: 7 7 7 7 7 7 7 7 6 5 4 3 2
simple rotate right 15: 7 7 7 7 7 7 7 7 7 6 5 4 3
simple rotate right 16: 7 7 7 7 7 7 7 7 7 7 6 5 4
simple rotate right 17: 7 7 7 7 7 7 7 7 7 7 7 6 5
simple rotate right 18: 7 7 7 7 7 7 7 7 7 7 7 7 6
simple rotate right 19: 7 7 7 7 7 7 7 7 7 7 7 7 7

Now I would like to have the same outcome with Arduino C++ but I don't want to use STL libraries because I have tried and it simply makes a mess.

Any ideas?  Queues, circle buffers, ring buffers, etc... ?
0
Comment
Question by:wfninpa
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 35

Accepted Solution

by:
sarabande earned 1000 total points
ID: 40311476
you may try the following code not using stl.

#include <stdio.h>

void fadeOn(int maxvalue, int maxlength) {
    int counter;
    int maxcounter = 1;
    int vtemp = 0;
    
    int v[] = {1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; 
    
    for (counter=1; counter < maxlength + maxvalue; counter++) {
      // simple rotation to the right
      
     printf ("simple rotate right %d", counter);
     for (int n = 0; n < 12; ++n)
          printf("%d ", n);
      printf("'\n");

      
      vtemp = v[0];
      for (int r = 11; r > 0; --r)
            v[r] = v[r-1];
      
      if (maxcounter < maxvalue) {
        v[0] = vtemp + 1;
      } else {
        v[0] = maxvalue;
      }
      
      maxcounter++;
    }
}

Open in new window


Sara
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question