Solved

Convert C++ to acceptable Arduino C++

Posted on 2014-09-08
1
125 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 34

Accepted Solution

by:
sarabande earned 500 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

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
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.

696 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