Arduino Custom Flasher Box for LED Light Bar

Discussion in 'Embedded Systems and Microcontrollers' started by Blenderite, Feb 2, 2016.

  1. Blenderite

    Thread Starter New Member

    Feb 2, 2016
    16
    0
    Hello Guys!!
    I am working on my first 'permanent' project. And I could use a little help.

    But first, a little back story:
    I got two sets of those el cheapo LED light bars off of ebay for free. I got them installed on my truck and was very disappointed with the flash patterns. A normal person would have just got a different flash box off of Amazon, but of course I opt to do things the hard way. I have an Arduino (UNO R3) laying around and in a moment of pure genius decided I should make my own flasher. Since the LED's run off the 12v straight from the car battery, I have a bank of 12 MOSFETs to switch the ground on and off for them. Hopefully that was a good choice. The plan is to have the 12v going into the Vin on the Arduino. Is that ok or should I through in a 5v voltage regulator? Then I bought on of the VKey Voltage Keypad off of SF and am planning on using that so that I can select from 12 different flash patterns.

    [​IMG]


    Here's the problem:
    How do I have a flash pattern running while checking to see if the user is pressing one of the other buttons to change the flash pattern?

    I am a little stumped here. I hope I don't have to have two Arduino to do this, one monitoring the keypad while the other controls the flash pattern.

    Any help/direction is greatly appreciated! Thanks
    Blenderite
     
  2. dannyf

    Well-Known Member

    Sep 13, 2015
    1,766
    355
    You can detect the user input in an interrupt. Or put the flashing in a timer interrupt, depending how fast it is.
     
  3. Blenderite

    Thread Starter New Member

    Feb 2, 2016
    16
    0
    The plan is to have the keypad being monitored constantly for changes. The flash patterns will be similar to road crew flash patterns, same sort of speed.

    Now the example code for the keypad does run on delay(50) so there is a little delay between checks. Which would be better suited for an interrupt?
     
  4. dannyf

    Well-Known Member

    Sep 13, 2015
    1,766
    355
    Interrupt on the user input, either external interrupt or change interrupt.
     
  5. Blenderite

    Thread Starter New Member

    Feb 2, 2016
    16
    0
    Alright I'll give it a shot. Thanks!
     
  6. Blenderite

    Thread Starter New Member

    Feb 2, 2016
    16
    0
  7. dannyf

    Well-Known Member

    Sep 13, 2015
    1,766
    355
    Use an adc interrupt.
     
  8. Blenderite

    Thread Starter New Member

    Feb 2, 2016
    16
    0
    I'll look it up. Thanks!
     
  9. Blenderite

    Thread Starter New Member

    Feb 2, 2016
    16
    0
    Do you know of a good tutorial/reference for ADC interrupt? All I am finding is digital pin interrupts.
     
  10. Hutkikz

    New Member

    Jan 29, 2016
    9
    1
    This can be handled using a switch/case statement.
    each case can be a step in your flash pattern and then in loop increment a counter variable to determine which step your at.
    that way while the arduino is waiting for the next step it will be free to check for button presses.

    Here is a example sketch that flashes 5 lights and 7 patterns, while checking a button and a pot.
    I was learning to use port manipulation, just pretend that the PORTD commands are digitalWrites and the PIND is digitalRead.
    Code (Text):
    1.  
    2. /*
    3. Greg's Flasher
    4.   Flasher unit for Greg's antique sign
    5. Version 2  Dec. 2015
    6. \\\\\\\\\\ Lights on Pins 3,4,5,6,7 /////////////////
    7. */
    8.  
    9. ////////////Output Pins 3,4,5,6,7 \\\\\\\\\\\\\\\\\
    10. const byte potPin = A0;  // Analog Input Pin
    11. byte patternStep, pattern, intervalModified;  // Counters/Flags
    12. unsigned long interval, starTime;  // Timing
    13.  
    14. void setup()
    15. {
    16.   Serial.begin(9600);
    17.   DDRD = 0xFA;  // Set Pins 1 & 3-7  As Outputs, Pins 0,2 as inputs
    18.   PORTD = 0xFC;  // Set INPUT_PULLUP on button, Initialize Outputs LOW
    19. }
    20.  
    21.  
    22. void loop()
    23. {
    24.   pattern += buttonCheck();  // Increment pattern when button pressed
    25.   if (pattern > 7) pattern = 0;
    26.   Serial.println(pattern);
    27.   unsigned long currenTime = millis();
    28.   if (currenTime - starTime >= interval)
    29.   {
    30.   patternStep++;
    31.   starTime += interval;
    32.   interval = potRead();
    33.   intervalModified = 0;
    34.   Serial.println("Time's up");
    35.   }
    36.  
    37.   switch (pattern) {
    38.   case 0:  // All On
    39.   PORTD |= 0xF8;  // Turn Off All Lights
    40.   Serial.println("0 executed");
    41.   break;
    42.   case 1:  
    43.   followTheLeader();
    44.   Serial.println("Pattern 1");
    45.   break;
    46.   case 2:
    47.   scanner();
    48.   break;
    49.   case 3:
    50.   negScanner();
    51.   break;
    52.   case 4:
    53.   upndown();
    54.   break;
    55.   case 5:
    56.   centerBloom();
    57.   break;
    58.   case 6:
    59.   all();
    60.   break;
    61.   case 7:  // All Off
    62.   PORTD |= 0xF8;  // Turn On All Lights
    63.   break;
    64.   }
    65. }
    66.  
    67.  
    68. int potRead()  // Sets Base Interval
    69. {
    70.   int potValue;
    71.  
    72.   potValue = analogRead(potPin);  // Read Potentiometer
    73.   potValue = map(potValue, 0, 1023, 850, 50);
    74.   return potValue;
    75. }
    76.  
    77.  
    78. byte buttonCheck()  // Return positive Once per press
    79. {
    80.   static int isButtonPressed = 0;
    81.  
    82.   if (!(PIND & (1 << PD2)))  // Read button on pin 2
    83.   {
    84.   isButtonPressed++;  // Increment Debounce variable
    85.   } else {
    86.   isButtonPressed = 0;  // Reset if it bounced
    87.   }
    88.  
    89.   if (isButtonPressed == 3)  // Debounce Confirmed Threshold
    90.   {
    91.   starTime = millis();  
    92.   patternStep = 0;  
    93.   PORTD = 0x04;  // Turn Off All Lights
    94.   return 1;  // Button Pressed
    95.   } else {
    96.   return 0;  // Button Not Pressed
    97.   }
    98. }
    99.  
    100.  
    101. void followTheLeader()  // Light up all the LEDs in turn then shut them off in turn
    102. {
    103.   switch (patternStep) {
    104.   case 0:  // | PATTERN |
    105.   PORTD &= ~0x08;  //  0 0 0 0 1  010
    106.   Serial.println("Step 0");
    107.   break;
    108.  
    109.   case 1:
    110.   PORTD &= ~0x10;  //  0 0 0 1 1  010
    111.   Serial.println("Step 1");
    112.   break;
    113.  
    114.   case 2:
    115.   PORTD &= ~0x20;  //  0 0 1 1 1  010
    116.   Serial.println("Step 2");
    117.   break;
    118.  
    119.   case 3:
    120.   PORTD &= ~0x40;  //  0 1 1 1 1  010
    121.   Serial.println("Step 3");
    122.   break;
    123.  
    124.   case 4:
    125.   PORTD &= ~0x80;  //  1 1 1 1 1  010
    126.   Serial.println("Step 4");
    127.   if (intervalModified == 0)
    128.   {
    129.   interval /= 4;  //  1/4 Interval
    130.   intervalModified = 1;
    131.   }
    132.   break;
    133.  
    134.   case 5:
    135.   PORTD |= 0x08;  //  1 1 1 1 0  010
    136.   Serial.println("Step 5");
    137.   break;
    138.  
    139.   case 6:
    140.   PORTD |= 0x10;  //  1 1 1 0 0  010
    141.   Serial.println("Step 6");
    142.   break;
    143.  
    144.   case 7:
    145.   PORTD |= 0x20;  //  1 1 0 0 0  010
    146.   Serial.println("Step 7");
    147.   break;
    148.  
    149.   case 8:
    150.   PORTD |= 0x40;  //  1 0 0 0 0  010
    151.   Serial.println("Step 8");
    152.   break;
    153.  
    154.   case 9:
    155.   PORTD |= 0x80;  //  0 0 0 0 0  010
    156.   patternStep = 0;
    157.   Serial.println("Step 9");
    158.   break;
    159.   }
    160. }
    161.  
    162.  
    163. void centerBloom()  // start in center expand then contract
    164. {
    165.   switch (patternStep)
    166.   {
    167.   case 0:
    168.   PORTD |= 0x20;  // Turns on LED #2 (pin 5)
    169.   break;
    170.   case 1:
    171.   PORTD |= 0x50;  // Turns on LED #1 & LED #3 (pins 4,6)
    172.   break;
    173.   case 2:
    174.   PORTD |= 0xf4;  // Turns on LED #0 & LED#4 (pins 3,7)
    175.   break;
    176.   interval *= 2;
    177.   case 3:
    178.   PORTD &= ~0xf4;  // Turn off LED #0 & LED#4 (pins 3,7)
    179.   break;
    180.   case 4:
    181.   PORTD &= ~0x50;  // Turn off LED #1 & LED #3 (pins 4,6)
    182.   break;
    183.   case 5:
    184.   PORTD &= ~0x20;  // Turn off LED #2 (pin 5)
    185.   patternStep = 0;
    186.   interval *= 2;
    187.   break;
    188.  
    189.   }
    190. }
    191.  
    192.  
    193. void scanner()
    194. {
    195.   switch (patternStep)
    196.   {
    197.   case 0:
    198.   PORTD = 0x10;  // LED #0 OFF(pin 3)& LED #1 ON(pin 4)
    199.   break;
    200.   case 1:
    201.   PORTD = 0x20;  // LED #1 OFF(pin 4)& LED #2 ON(pin 5)
    202.   break;
    203.   case 2:
    204.   PORTD = 0x40;  // LED #2 OFF(pin 5)& LED #3 ON(pin 6)
    205.   break;
    206.   case 3:
    207.   PORTD = 0x80;  // LED #3 OFF(pin 6)& LED #4 ON(pin 7)
    208.   interval *= 2;
    209.   break;
    210.   case 4:
    211.   PORTD = 0x40;  // LED #3 ON(pin 6)& LED #4 OFF(pin 7)
    212.   break;
    213.   case 5:
    214.   PORTD = 0x20;  // LED #2 ON(pin 5)& LED #3 OFF(pin 6)
    215.   break;
    216.   case 6:
    217.   PORTD = 0x10;  // LED #1 ON(pin 4)& LED #2 OFF(pin 5)
    218.   break;
    219.   case 7:
    220.   PORTD = 0x08;  // LED #0 ON(pin 3)& LED #1 OFF(pin 4)
    221.   patternStep = 0;
    222.   break;
    223.   }
    224. }
    225.  
    226.  
    227. void negScanner()
    228. {
    229.   switch (patternStep)
    230.   {
    231.   case 0:
    232.   PORTD = 0xf0;
    233.   break;
    234.   case 1:
    235.   PORTD = 0xE8;
    236.   break;
    237.   case 2:
    238.   PORTD = 0xD8;
    239.   break;
    240.   case 3:
    241.   PORTD = 0xB8;
    242.   case 4:
    243.   PORTD = 0x78;
    244.   interval *= 2;
    245.   break;
    246.   case 5:
    247.   PORTD = 0xB8;
    248.   break;
    249.   case 6:
    250.   PORTD = 0xD8;
    251.   break;
    252.   case 7:
    253.   PORTD = 0xE8;
    254.   break;
    255.   case 8:
    256.   PORTD = 0x08;
    257.   interval *= 2;
    258.   patternStep = 0;
    259.   break;
    260.   }
    261. }
    262.  
    263.  
    264. void upndown()
    265. {
    266.   switch (patternStep)
    267.   {
    268.   case 0:
    269.   PORTD |= 0x08;
    270.   break;
    271.   case 1:
    272.   PORTD |= 0x10;
    273.   break;
    274.   case 2:
    275.   PORTD |= 0x20;
    276.   break;
    277.   case 3:
    278.   PORTD |= 0x40;
    279.   break;
    280.   case 4:
    281.   PORTD |= 0x80;
    282.   break;
    283.   case 5:
    284.   PORTD &= ~0x80;
    285.   break;
    286.   case 6:
    287.   PORTD &= ~0x40;
    288.   break;
    289.   case 7:
    290.   PORTD &= ~0x20;
    291.   break;
    292.   case 8:
    293.   PORTD &= ~0x10;
    294.   break;
    295.   case 9:
    296.   PORTD &= ~0x08;
    297.   patternStep = 0;
    298.   break;
    299.   }
    300. }
    301.  
    302.  
    303.  
     
  11. BillB3857

    Senior Member

    Feb 28, 2009
    2,400
    348
  12. Blenderite

    Thread Starter New Member

    Feb 2, 2016
    16
    0
    Yes, that is what I am doing, but the problem is that I have to constantly monitor that variable to see if it changes. I tried it with simple coding and it 'works', but it could take several attempts to change patterns. You basically have to land the button press between when it checks for any changes in the variable and when it starts the flash pattern. Here is the code that does that:

    Code (Text):
    1.  
    2. #include <VKey.h>
    3.  
    4. VKey keypad(A1, VKey::FIVE);
    5.  
    6. int brightness = 0;
    7. int fadeAmount = 225;
    8. int buttonPin = 2;
    9. int buttonState = 0;
    10. int sequence = 0;
    11.  
    12. int newKey = 0;
    13. int currentKey;
    14.  
    15. void setup() {
    16.   // initialize digital pin 13 as an output.
    17.   pinMode(13, OUTPUT);
    18.   pinMode(12, OUTPUT);
    19.   pinMode(11, OUTPUT);
    20.   pinMode(10, OUTPUT);
    21.   pinMode(9, OUTPUT);
    22.   pinMode(8, OUTPUT);
    23.   pinMode(7, OUTPUT);
    24.   pinMode(6, OUTPUT);
    25.   pinMode(5, OUTPUT);
    26.   pinMode(4, OUTPUT);
    27.   pinMode(3, OUTPUT);
    28.   pinMode(2, OUTPUT);
    29. }
    30.  
    31. // the loop function runs over and over again forever
    32. void loop() {
    33.   VKey::eKeynum k;
    34.   if(keypad.checkKeys(k)){
    35.     newKey = k;
    36.   }
    37.   if(newKey != 0){
    38.     if(newKey != currentKey){
    39.       currentKey = newKey;
    40.     }
    41.   }
    42. //---Post Interupt---//
    43.   if(currentKey == 1){
    44.     patternOne();
    45.   }
    46.   if(currentKey == 2){
    47.     patternTwo();
    48.   }
    49.   if(currentKey == 3){
    50.     patternThree();
    51.   }
    52.   if(currentKey == 4){
    53.     patternFour();
    54.   }
    55.   if(currentKey == 5){
    56.     patternFive();
    57.   }
    58.   if(currentKey == 6){
    59.     patternSix();
    60.   }
    61.   if(currentKey == 7){
    62.     patternSeven();
    63.   }
    64.   if(currentKey == 8){
    65.     patternEight();
    66.   }
    67.   if(currentKey == 9){
    68.     patternNine();
    69.   }
    70.   if(currentKey == 10){
    71.     patternTen();
    72.   }
    73.   if(currentKey == 11){
    74.     patternEleven();
    75.   }
    76. //  if(currentKey == 12){
    77. //    patternTweleve();
    78. //  }
    79. //
    80. }
    81.  
    82. void patternOne() {
    83.   digitalWrite(7, HIGH);
    84.   digitalWrite(5, HIGH);
    85.   delay(100);
    86.   digitalWrite(7, LOW);
    87.   digitalWrite(5, LOW);
    88.   digitalWrite(6, HIGH);
    89.   digitalWrite(4, HIGH);
    90.   delay(100);
    91.   digitalWrite(6, LOW);
    92.   digitalWrite(4, LOW);
    93.   delay(100);
    94. }
    95.  
    96. void patternTwo() {
    97.   digitalWrite(13, HIGH);
    98.   digitalWrite(9, HIGH);
    99.   digitalWrite(11, HIGH);
    100.   delay(100);
    101.   digitalWrite(13, LOW);
    102.   digitalWrite(9, LOW);
    103.   digitalWrite(11, LOW);
    104.   digitalWrite(10, HIGH);
    105.   digitalWrite(12, HIGH);
    106.   digitalWrite(8, HIGH);
    107.   delay(100);
    108.   digitalWrite(10, LOW);
    109.   digitalWrite(12, LOW);
    110.   digitalWrite(8, LOW);
    111.   delay(100);
    112. }
    113.  
    114. void patternThree() {
    115.   digitalWrite(3, HIGH);
    116.   delay(100);
    117.   digitalWrite(3, LOW);
    118.   digitalWrite(2, HIGH);
    119.   delay(100);
    120.   digitalWrite(2, LOW);
    121.   delay(100);
    122. }
    123.  
    124. void patternFour() {
    125.   digitalWrite(3, HIGH);
    126.   digitalWrite(7, HIGH);
    127.   digitalWrite(5, HIGH);
    128.   digitalWrite(13, HIGH);
    129.   digitalWrite(9, HIGH);
    130.   digitalWrite(11, HIGH);
    131.   delay(100);
    132.   digitalWrite(3, LOW);
    133.   digitalWrite(2, HIGH);
    134.   digitalWrite(7, LOW);
    135.   digitalWrite(5, LOW);
    136.   digitalWrite(6, HIGH);
    137.   digitalWrite(4, HIGH);
    138.   digitalWrite(13, LOW);
    139.   digitalWrite(9, LOW);
    140.   digitalWrite(11, LOW);
    141.   digitalWrite(10, HIGH);
    142.   digitalWrite(12, HIGH);
    143.   digitalWrite(8, HIGH);
    144.   delay(100);
    145.   digitalWrite(6, LOW);
    146.   digitalWrite(4, LOW);
    147.   digitalWrite(10, LOW);
    148.   digitalWrite(12, LOW);
    149.   digitalWrite(8, LOW);
    150.   digitalWrite(2, LOW);
    151.   delay(100);
    152. }
    153.  
    154. void patternFive() {
    155.   digitalWrite(13, HIGH);
    156.   digitalWrite(7, HIGH);
    157.   delay(125);
    158.   digitalWrite(13, LOW);
    159.   digitalWrite(7, LOW);
    160.   delay(125);
    161.   digitalWrite(8, HIGH);
    162.   digitalWrite(12, HIGH);
    163.   delay(125);
    164.   digitalWrite(8, LOW);
    165.   digitalWrite(12, LOW);
    166.   delay(125);
    167.   digitalWrite(11, HIGH);
    168.   digitalWrite(9, HIGH);
    169.   delay(125);
    170.   digitalWrite(11, LOW);
    171.   digitalWrite(9, LOW);
    172.   delay(125);
    173.   digitalWrite(10, HIGH);
    174.   delay(125);
    175.   digitalWrite(10, LOW);
    176.   delay(125);
    177. }
    178.  
    179. void patternSix() {
    180.   digitalWrite(13, HIGH);
    181.   digitalWrite(7, HIGH);
    182.   delay(500);
    183.   digitalWrite(12, HIGH);
    184.   digitalWrite(8, HIGH);
    185.   delay(500);
    186.   digitalWrite(11, HIGH);
    187.   digitalWrite(9, HIGH);
    188.   delay(500);
    189.   digitalWrite(10, HIGH);
    190.   delay(500);
    191.   digitalWrite(13, LOW);
    192.   delay(50);
    193.   digitalWrite(13, HIGH);
    194.   delay(50);
    195.   digitalWrite(13, LOW);
    196.   delay(50);
    197.   digitalWrite(13, HIGH);
    198.   delay(50);
    199.   digitalWrite(9, LOW);
    200.   delay(50);
    201.   digitalWrite(9, HIGH);
    202.   delay(50);
    203.   digitalWrite(9, LOW);
    204.   delay(50);
    205.   digitalWrite(11, HIGH);
    206.   delay(50);
    207.   digitalWrite(11, LOW);
    208.   delay(50);
    209.   digitalWrite(11, HIGH);
    210.   delay(50);
    211.   digitalWrite(8, LOW);
    212.   delay(50);
    213.   digitalWrite(8, HIGH);
    214.   delay(50);
    215.   digitalWrite(13, LOW);
    216.   digitalWrite(7, LOW);
    217.   digitalWrite(12, LOW);
    218.   digitalWrite(8, LOW);
    219.   digitalWrite(11, LOW);
    220.   digitalWrite(9, LOW);
    221.   digitalWrite(10, LOW);
    222.   delay(500);
    223. }
    224.  
    225. void patternSeven(){
    226.   digitalWrite(13, HIGH);
    227.   digitalWrite(12, HIGH);
    228.   digitalWrite(11, HIGH);
    229.   delay(100);
    230.   digitalWrite(13, LOW);
    231.   digitalWrite(12, LOW);
    232.   digitalWrite(11, LOW);
    233.   delay(100);
    234.   digitalWrite(13, HIGH);
    235.   digitalWrite(12, HIGH);
    236.   digitalWrite(11, HIGH);
    237.   delay(100);
    238.   digitalWrite(13, LOW);
    239.   digitalWrite(12, LOW);
    240.   digitalWrite(11, LOW);
    241.   delay(100);
    242.   digitalWrite(7, HIGH);
    243.   digitalWrite(8, HIGH);
    244.   digitalWrite(9, HIGH);
    245.   delay(100);
    246.   digitalWrite(7, LOW);
    247.   digitalWrite(8, LOW);
    248.   digitalWrite(9, LOW);
    249.   delay(100);
    250.   digitalWrite(7, HIGH);
    251.   digitalWrite(8, HIGH);
    252.   digitalWrite(9, HIGH);
    253.   delay(100);
    254.   digitalWrite(7, LOW);
    255.   digitalWrite(8, LOW);
    256.   digitalWrite(9, LOW);
    257.   delay(100);
    258. }
    259.  
    260. void patternEight(){
    261.   digitalWrite(13, HIGH);
    262.   digitalWrite(12, HIGH);
    263.   digitalWrite(11, HIGH);
    264.   delay(50);
    265.   digitalWrite(13, LOW);
    266.   digitalWrite(12, LOW);
    267.   digitalWrite(11, LOW);
    268.   delay(50);
    269.   digitalWrite(13, HIGH);
    270.   digitalWrite(12, HIGH);
    271.   digitalWrite(11, HIGH);
    272.   delay(50);
    273.   digitalWrite(13, LOW);
    274.   digitalWrite(12, LOW);
    275.   digitalWrite(11, LOW);
    276.   delay(100);
    277.   digitalWrite(7, HIGH);
    278.   digitalWrite(8, HIGH);
    279.   digitalWrite(9, HIGH);
    280.   delay(50);
    281.   digitalWrite(7, LOW);
    282.   digitalWrite(8, LOW);
    283.   digitalWrite(9, LOW);
    284.   delay(50);
    285.   digitalWrite(7, HIGH);
    286.   digitalWrite(8, HIGH);
    287.   digitalWrite(9, HIGH);
    288.   delay(50);
    289.   digitalWrite(7, LOW);
    290.   digitalWrite(8, LOW);
    291.   digitalWrite(9, LOW);
    292.   delay(100);
    293. }
    294.  
    295. void patternNine(){
    296.   digitalWrite(13, HIGH);
    297.   digitalWrite(12, HIGH);
    298.   digitalWrite(11, HIGH);
    299.   delay(30);
    300.   digitalWrite(13, LOW);
    301.   digitalWrite(12, LOW);
    302.   digitalWrite(11, LOW);
    303.   delay(30);
    304.   digitalWrite(13, HIGH);
    305.   digitalWrite(12, HIGH);
    306.   digitalWrite(11, HIGH);
    307.   delay(30);
    308.   digitalWrite(13, LOW);
    309.   digitalWrite(12, LOW);
    310.   digitalWrite(11, LOW);
    311.   delay(50);
    312.   digitalWrite(7, HIGH);
    313.   digitalWrite(8, HIGH);
    314.   digitalWrite(9, HIGH);
    315.   delay(30);
    316.   digitalWrite(7, LOW);
    317.   digitalWrite(8, LOW);
    318.   digitalWrite(9, LOW);
    319.   delay(30);
    320.   digitalWrite(7, HIGH);
    321.   digitalWrite(8, HIGH);
    322.   digitalWrite(9, HIGH);
    323.   delay(30);
    324.   digitalWrite(7, LOW);
    325.   digitalWrite(8, LOW);
    326.   digitalWrite(9, LOW);
    327.   delay(50);
    328. }
    329.  
    330. void patternTen(){
    331.   digitalWrite(13, HIGH);
    332.   digitalWrite(7, HIGH);
    333.   delay(250);
    334.   digitalWrite(13, LOW);
    335.   digitalWrite(7, LOW);
    336.   delay(50);
    337.   digitalWrite(12, HIGH);
    338.   digitalWrite(8, HIGH);
    339.   delay(250);
    340.   digitalWrite(12, LOW);
    341.   digitalWrite(8, LOW);
    342.   delay(50);
    343.   digitalWrite(11, HIGH);
    344.   digitalWrite(9, HIGH);
    345.   delay(250);
    346.   digitalWrite(11, LOW);
    347.   digitalWrite(9, LOW);
    348.   delay(50);
    349.   digitalWrite(10, HIGH);
    350.   delay(250);
    351.   digitalWrite(10, LOW);
    352.   delay(50);
    353. }
    354.  
    355. void patternEleven(){
    356.   digitalWrite(13, HIGH);
    357.   digitalWrite(7, HIGH);
    358.   delay(100);
    359.   digitalWrite(13, LOW);
    360.   digitalWrite(7, LOW);
    361.   delay(50);
    362.   digitalWrite(12, HIGH);
    363.   digitalWrite(8, HIGH);
    364.   delay(100);
    365.   digitalWrite(12, LOW);
    366.   digitalWrite(8, LOW);
    367.   delay(50);
    368.   digitalWrite(11, HIGH);
    369.   digitalWrite(9, HIGH);
    370.   delay(100);
    371.   digitalWrite(11, LOW);
    372.   digitalWrite(9, LOW);
    373.   delay(50);
    374.   digitalWrite(10, HIGH);
    375.   delay(100);
    376.   digitalWrite(10, LOW);
    377.   delay(50);
    378. }
    379.  
    380. void patternTwelve(){
    381. }
    382.  
     
  13. dannyf

    Well-Known Member

    Sep 13, 2015
    1,766
    355
    in cases like this, this is the gist of what you do:

    1) determine how fast you want to detect the keypad. let's say 10ms. the longer the interval, the less "responsive" the keypad is and the lower the cpu load is.

    2) in the adc interrupt, detect if the keypad is pressed -> adc value within a range;
    2.a) if you need to debounce the keypad, you may wait for a set pattern to show up.

    3) once the adc result has been read, start the next adc;

    4) once the keypad is pressed, with or without debounce, process the key press.

    5) exit.

    With that, your main loop run nothing but your flashing code. Which actually can also be executed from a timer isr as well.
     
  14. Blenderite

    Thread Starter New Member

    Feb 2, 2016
    16
    0
    That is lovely and all, however I am not finding any information on an *ANALOG* (ADC) interrupt . I have Googled every combination that I can find. Even looked on the Arduino site. Checked YouTube. Even checked the lawn out front. Zilch.

    Does anyone know of a site that has a good explanation of how to code a ADC interrupt?
     
  15. Blenderite

    Thread Starter New Member

    Feb 2, 2016
    16
    0
    Well, gee. Ever since this thread got moved, I have gotten no response. Thanks a lot ScottWang, you are so helpful.
     
  16. BillB3857

    Senior Member

    Feb 28, 2009
    2,400
    348
    Last edited: Feb 4, 2016
  17. Blenderite

    Thread Starter New Member

    Feb 2, 2016
    16
    0
    I am still a little confused as to what exactly I need to use. I would really like to see something in the Arduino reference, cause it actually does a good job explaining stuff.
     
  18. BillB3857

    Senior Member

    Feb 28, 2009
    2,400
    348
  19. BillB3857

    Senior Member

    Feb 28, 2009
    2,400
    348
  20. Blenderite

    Thread Starter New Member

    Feb 2, 2016
    16
    0
    I'll take a look at all these, thanks!
     
Loading...