Solved

Convert C++ to acceptable Arduino C++

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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Decoding 32 bit binary streams 6 54
Beginner to Unreal Engine 4 5 107
Copy output image from TWindowsMediaPlayer 6 55
Where are the c++ header files to use in Eclipse? 4 53
When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

730 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