daily pastebin goal
95%
SHARE
TWEET

Untitled

a guest Feb 2nd, 2019 70 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #define led1R 2
  2. #define led1B 3
  3. #define led1G 4
  4.  
  5. #define led2R 5
  6. #define led2B 6
  7. #define led2G 7
  8.  
  9. #define led3R 8
  10. #define led3B 9
  11. #define led3G 10
  12.  
  13. #define led4R 14
  14. #define led4B 15
  15. #define led4G 16
  16.  
  17. #define led5R 17
  18. #define led5B 18
  19. #define led5G 19
  20.  
  21. #define RPMInput 12
  22.  
  23. int RPM = 0;
  24. bool debug = false;
  25.  
  26. void startUpAnimation() {
  27.   digitalWrite(led1B, HIGH);
  28.   delay(100);
  29.   digitalWrite(led2B, HIGH);
  30.   delay(100);
  31.   digitalWrite(led3B, HIGH);
  32.   delay(100);
  33.   digitalWrite(led4B, HIGH);
  34.   delay(100);
  35.   digitalWrite(led5B, HIGH);
  36.  
  37.   delay(500);
  38.  
  39.   digitalWrite(led5B, LOW);
  40.   delay(100);
  41.   digitalWrite(led4B, LOW);
  42.   delay(100);
  43.   digitalWrite(led3B, LOW);
  44.   delay(100);
  45.   digitalWrite(led2B, LOW);
  46.   delay(100);
  47.   digitalWrite(led1B, LOW);
  48.  
  49.   delay(500);
  50.  
  51.   digitalWrite(led1R, HIGH);
  52.   digitalWrite(led2R, HIGH);
  53.   digitalWrite(led3R, HIGH);
  54.   digitalWrite(led4R, HIGH);
  55.   digitalWrite(led5R, HIGH);
  56.   delay(200);
  57.  
  58.   resetPins();
  59.   delay(100);
  60.  
  61.   digitalWrite(led1B, HIGH);
  62.   digitalWrite(led2B, HIGH);
  63.   digitalWrite(led3B, HIGH);
  64.   digitalWrite(led4B, HIGH);
  65.   digitalWrite(led5B, HIGH);
  66.   delay(200);
  67.  
  68.   resetPins();
  69.  
  70.   delay(1000);
  71. }
  72.  
  73. void noSignal() {
  74.   resetPins();
  75.   Serial.println("No signal");
  76.   digitalWrite(led1R, HIGH);
  77.   digitalWrite(led2G, HIGH);
  78.   digitalWrite(led3B, HIGH);
  79.   digitalWrite(led4R, HIGH);
  80.   digitalWrite(led5G, HIGH);
  81.  
  82.   delay(500);
  83.  
  84.   resetPins();
  85.  
  86.   digitalWrite(led1B, HIGH);
  87.   digitalWrite(led2R, HIGH);
  88.   digitalWrite(led3G, HIGH);
  89.   digitalWrite(led4B, HIGH);
  90.   digitalWrite(led5R, HIGH);
  91.  
  92.   delay(500);
  93.  
  94.   resetPins();
  95.  
  96.   digitalWrite(led1G, HIGH);
  97.   digitalWrite(led2B, HIGH);
  98.   digitalWrite(led3R, HIGH);
  99.   digitalWrite(led4G, HIGH);
  100.   digitalWrite(led5B, HIGH);
  101.  
  102.   delay(500);
  103.  
  104. }
  105.  
  106. void RPM1k() {
  107.   resetPins();
  108.   digitalWrite(led1B, HIGH);
  109. }
  110.  
  111. void RPM2k() {
  112.   resetPins();
  113.   digitalWrite(led1B, HIGH);
  114.   digitalWrite(led2B, HIGH);
  115. }
  116.  
  117. void RPM3k() {
  118.   resetPins();
  119.   digitalWrite(led1B, HIGH);
  120.   digitalWrite(led2B, HIGH);
  121.   digitalWrite(led3B, HIGH);
  122. }
  123.  
  124. void RPM4k() {
  125.   resetPins();
  126.   digitalWrite(led1B, HIGH);
  127.   digitalWrite(led2B, HIGH);
  128.   digitalWrite(led3B, HIGH);
  129.   digitalWrite(led4R, HIGH);
  130. }
  131.  
  132. void RPM5k() {
  133.   resetPins();
  134.   digitalWrite(led1R, HIGH);
  135.   digitalWrite(led2R, HIGH);
  136.   digitalWrite(led3R, HIGH);
  137.   digitalWrite(led4R, HIGH);
  138.   digitalWrite(led5R, HIGH);
  139. }
  140.  
  141. void RPM6k() {
  142.   resetPins();
  143.   digitalWrite(led1R, HIGH);
  144.   digitalWrite(led2R, HIGH);
  145.   digitalWrite(led3R, HIGH);
  146.   digitalWrite(led4R, HIGH);
  147.   digitalWrite(led5R, HIGH);
  148.  
  149.   delay(200);
  150.  
  151.   digitalWrite(led1R, LOW);
  152.   digitalWrite(led2R, LOW);
  153.   digitalWrite(led3R, LOW);
  154.   digitalWrite(led4R, LOW);
  155.   digitalWrite(led5R, LOW);
  156.  
  157.   delay(200);
  158. }
  159.  
  160. void RPM65k() {
  161.   resetPins();
  162.   digitalWrite(led1R, HIGH);
  163.   digitalWrite(led2R, HIGH);
  164.   digitalWrite(led3R, HIGH);
  165.   digitalWrite(led4R, HIGH);
  166.   digitalWrite(led5R, HIGH);
  167.  
  168.   delay(50);
  169.  
  170.   digitalWrite(led1R, LOW);
  171.   digitalWrite(led2R, LOW);
  172.   digitalWrite(led3R, LOW);
  173.   digitalWrite(led4R, LOW);
  174.   digitalWrite(led5R, LOW);
  175.  
  176.   delay(50);
  177. }
  178.  
  179. void resetPins() {
  180.   for (int i = 2; i < 11; i++) {
  181.     digitalWrite(i, LOW);
  182.   }
  183.   for (int i = 14; i < 20; i++) {
  184.     digitalWrite(i, LOW);
  185.   }
  186. }
  187.  
  188. int currentRPM() {
  189.   if (!debug) {
  190.     long pulseDuration = pulseIn(RPMInput, HIGH);
  191.     return 60000000 / pulseDuration / 6 * 1.75 -1500;
  192.   }
  193.  
  194.   RPM += 1000;
  195.   return RPM;
  196. }
  197.  
  198. void setup() {
  199.   //define pin output
  200.   for (int i = 2; i < 11; i++) {
  201.     pinMode(i, OUTPUT);
  202.   }
  203.   for (int i = 14; i < 20; i++) {
  204.     pinMode(i, OUTPUT);
  205.   }
  206.  
  207.   Serial.begin(9600);
  208.  
  209.   startUpAnimation();
  210. }
  211.  
  212. void loop() {
  213.   RPM = currentRPM();
  214.   Serial.println(RPM);
  215.  
  216.   if (RPM < 2000 && RPM >= 1000) {
  217.     RPM1k();
  218.   }
  219.  
  220.   if (RPM < 3000 && RPM >= 2000) {
  221.     RPM2k();
  222.   }
  223.  
  224.   if (RPM < 4000 && RPM >= 3000) {
  225.     RPM3k();
  226.   }
  227.  
  228.   if (RPM < 5000 && RPM >= 4000) {
  229.     RPM4k();
  230.   }
  231.  
  232.   if (RPM < 6000 && RPM >= 5000) {
  233.     RPM5k();
  234.   }
  235.  
  236.   if (RPM > 6400 && RPM >= 6000) {
  237.     RPM6k();
  238.   }
  239.  
  240.     if (RPM >= 6400) {
  241.     RPM65k();
  242.   }
  243.  
  244.   if (RPM == -1) {
  245.     noSignal();
  246.   }
  247.  
  248.   if (debug) {
  249.     delay(1000);
  250.     if (RPM > 7000) {
  251.       RPM = 1000;
  252.     }
  253.   }
  254. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top