Advertisement
Guest User

CreateColorGradiantFromRefArrayBenchmark

a guest
May 28th, 2015
335
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.93 KB | None | 0 0
  1. #include <Average.h>
  2.  
  3. #define WAIT_FOR_KEYBOARD 1
  4.  
  5. int xMax = 16;
  6. int yMax = 16;
  7. int spread = 1;
  8. int startX = 0;
  9. int startY = 0;
  10. int stopX = (yMax * spread) - 1;
  11. int stopY = (yMax * spread) - 1;
  12. int A = (stopX - startX);
  13. int B = (stopY - startY);
  14. int C1 = 0;
  15. int C2 = 450;
  16. const int refArraySize = 32;
  17. const int refArray[refArraySize] = { 285, 285, 285, 270, 240, 210, 180, 165, 165, 165, 165, 180, 210, 240, 270, 285, 150, 165, 165, 165, 165, 150, 120, 90, 60, 45, 45, 45, 45, 60, 90, 120 };
  18. int C = 0;
  19.  
  20. int start_color = 0;
  21. int end_color = 255;
  22. int color = 0;
  23.  
  24.  
  25. int previousAveHeading = 0;
  26. int previousHeading = 0;
  27. int shiftX = 0;
  28. int shiftY = 0;
  29.  
  30.  
  31. void setup()
  32. {
  33. if (WAIT_FOR_KEYBOARD) {
  34. Serial.begin(9600);
  35. // Wait for serial to initalize.
  36. while (!Serial) {}
  37.  
  38. Serial.println("Strike any key to start...");
  39. // Wait for the next keystroke.
  40. while (!Serial.available()) {}
  41.  
  42. // Clear the serial buffer.
  43. Serial.read();
  44. }
  45. }
  46.  
  47.  
  48. Average<float> ave(100);
  49. long totalTime = 0;
  50. boolean benchLoop = true;
  51. int j = 0;
  52.  
  53.  
  54. void loop()
  55. {
  56. while(benchLoop){
  57. long startTime = micros();
  58. ShowGradient();
  59. long endTime = micros();
  60. totalTime = endTime - startTime;
  61. ave.push(totalTime);
  62. j++;
  63. if(j >= 100){
  64. benchLoop = false;
  65. }
  66. }
  67. Serial.println(ave.mean());
  68. delay(5000000);
  69. }
  70.  
  71.  
  72.  
  73. void ShowGradient() {
  74. for(int shiftX = 0; shiftX < (stopX * 4 * spread) ; shiftX++){
  75. for (int i = 0; i < refArraySize; i++){
  76. C = refArray[i] + (15 * shiftX);
  77. if (C > C2){
  78. C = C2 - (C - C2);
  79. }
  80. if (C < C1){
  81. C = C1 - (C - C1);
  82. }
  83. color = map(C,C1,C2,start_color,end_color);
  84. }
  85. }
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement