8 Step CV Sequencer // Nano // Foward Trigger Issue

Hi together,

as i seriously want to accomplish this project i need some community help.

I´ve picked the code from "LookMumNoComputer" page and i´m having a hard time with getting it to run properly.

My small codermind found some tiny mistakes like flipped buttons or useless declarations, so i´m questioning myself if there are more issues i can´t figure out.

The code should behave like a kind of 4017 timer every time it gets a HIGH on Pin12 or Pin13
This ain´t working as it seems.
I´ve flipped and swapped the pins to make sure it´s not a phsysical issue of the pins, but nope ...

What i can say, the buttons and corresponding digital outs do work as intended, but the inputs for forwarding etc. dont work.

Luckily the code is very slim and the bahaviour of a 4017 timer chip should not be a big deal as i guess.
But already too big for me :cry:

So my question,
is this code theoretically doin what it should?

This here seems to do nothing?

void loop ()
{
val1 = digitalRead (FORWARDS);
if((val1 == HIGH) && (old_val1 == LOW))

{
newled = led - 1;
if (newled <=8) { newled = 16; }
led = newled;

}

as a try i reduced everything to the main function forwarding the digital pins, but i´m not getting it.

here´s the original code and i would be very thankfull if someone could dive in for a minute...

//


#define STEP1 2
#define STEP2 3
#define STEP3 4
#define STEP4 5
#define STEP5 6
#define STEP6 7
#define STEP7 8
#define STEP8 9
#define STEPBUTTON1   14
#define STEPBUTTON2   15
#define STEPBUTTON3   16
#define STEPBUTTON4   17
#define STEPBUTTON5   18
#define STEPBUTTON6   19
#define STEPBUTTON7   21
#define STEPBUTTON8   20

#define FORWARDS 12
#define VARIATION 19
#define RESET 10
#define BACK 13
#define ZERO 11

//ABOVE BASICALLY DEFINES THE NAMES OF THE PINS, PLEASE REMEMBER THE ANALOG PINS A0,A1,A2, BLAH BLAH CAN BE USED AS DIGITAL PINS. THE ARE
//DIGITAL 14 and UP!


int val = 0;
int old_val = 0;
int val1 = 0;
int old_val1 = 0;
int val2 = 0;
int old_val2 = 0;
int val3 = 0;
int old_val3 = 0;
int val4 = 0;
int old_val4 = 0;


int vals1 = 0;
int old_vals1 = 0;
int vals2 = 0;
int old_vals2 = 0;
int vals3 = 0;
int old_vals3 = 0;
int vals4 = 0;
int old_vals4 = 0;
int vals5 = 0;
int old_vals5 = 0;
int vals6 = 0;
int old_vals6 = 0;
int vals7 = 0;
int old_vals7 = 0;
int vals8 = 0;
int old_vals8 = 0;


int state = 0;
int led = 17;
int newled = 1;


void setup ()
{
  pinMode (STEP1, OUTPUT);
  pinMode (STEP2, OUTPUT);
  pinMode (STEP3, OUTPUT);
  pinMode (STEP4, OUTPUT);
  pinMode (STEP5, OUTPUT);
  pinMode (STEP6, OUTPUT);
  pinMode (STEP7, OUTPUT);
  pinMode (STEP8, OUTPUT);
  pinMode (FORWARDS, INPUT);
  pinMode (BACK, INPUT);
  pinMode (RESET, INPUT);
  pinMode (ZERO, INPUT);
  pinMode (STEPBUTTON1, INPUT);
  pinMode (STEPBUTTON2, INPUT);
  pinMode (STEPBUTTON3, INPUT);
  pinMode (STEPBUTTON4, INPUT);
  pinMode (STEPBUTTON5, INPUT);
  pinMode (STEPBUTTON6, INPUT);

  //SET THE PINS TO IN OR OUT
  

}


void loop ()
{  
  val1 = digitalRead (FORWARDS);
   if((val1 == HIGH) && (old_val1 == LOW))
   
   {
    newled = led - 1; 
     if (newled <=8) { newled = 16; } 
    led = newled;
   
   }

//THIS IS THE THING THAT MAKES IT GO FORWARDS, IT SAYS -1 YOULL SEE ALL OF THE NUMBERS AND WHAT THEY DO BELOW
   
       val2 = digitalRead (ZERO);
   if((val2 == HIGH) && (old_val2 == LOW))
   
   {
    newled = led = 17;
    led = newled;
   }
  
//THIS MAKES THE ZERO COMMAND WORK. 17 IS WHEN NO LIGHTS ARE ON 
   
    val3 = digitalRead (RESET);
   if((val3 == HIGH) && (old_val3 == LOW))
   
   {
    newled = led = 16;
    led = newled;
   }

//RESET BACK TO STEP 1

     val4 = digitalRead (BACK);
   if((val4 == HIGH) && (old_val4 == LOW))
   
   {
    newled = led + 1; 
     if (newled >=17 ) { newled = 9; } 
    led = newled;
   
   }

//GO BACKWARDS

//BELOW ARE ALL OF THE STEP BUTTONS AND WHAT THEY DO. BASICALLY WHEN THEY ARE HIT THE LED NUMBER GOES TO THE RIGHT NUMBER

     vals1 = digitalRead (STEPBUTTON1);
   if((vals1 == HIGH) && (old_vals1 == LOW))
   
   {
    newled = led = 16;
   
   }
    
     vals2 = digitalRead (STEPBUTTON2);
   if((vals2 == HIGH) && (old_vals2 == LOW))
   
   {
    newled = led = 15;
   
   }

     vals3 = digitalRead (STEPBUTTON3);
   if((vals3 == HIGH) && (old_vals3 == LOW))
   
   {
    newled = led = 14;
   
   }

     vals4 = digitalRead (STEPBUTTON4);
   if((vals4 == HIGH) && (old_vals4 == LOW))
   
   {
    newled = led = 13;
   
   }
   

     vals5 = digitalRead (STEPBUTTON5);
   if((vals5 == HIGH) && (old_vals5 == LOW))
   
   {
    newled = led = 12;
   
   }
   
     vals6 = digitalRead (STEPBUTTON6);
   if((vals6 == HIGH) && (old_vals6 == LOW))
   
   {
    newled = led = 11;
   
   }

     vals7 = analogRead (STEPBUTTON7);
   if((vals7 >= 1000) && (old_vals7 <= 1000))
   
   {
    newled = led = 10;
   
   }
  
      vals8 = analogRead (STEPBUTTON8);
   if((vals8 >= 1000) && (old_vals8 <= 1000))
   
   {
    newled = led = 9;
   
   }
  
  old_val = val;
  old_val1 = val1;
  old_val2 = val2;
  old_val3 = val3;
  old_val4 = val4;


  if (newled >=17 ) { newled = 9; } 
  if (newled <=8 ) { newled = 16; } 
  
      

  
 //BELOW ARE ALL OF THE NU<BERS AND WHAT THEY DO!
 
  if (led == 17)
  {
    digitalWrite(STEP1, LOW);
    digitalWrite(STEP2, LOW);
    digitalWrite(STEP3, LOW);
    digitalWrite(STEP4, LOW);
    digitalWrite(STEP5, LOW);
    digitalWrite(STEP6, LOW);
    digitalWrite(STEP7, LOW);
    digitalWrite(STEP8, LOW);
  }
 
  if (led == 16)
  {
    digitalWrite(STEP1, HIGH);
    digitalWrite(STEP2, LOW);
    digitalWrite(STEP3, LOW);
    digitalWrite(STEP4, LOW);
    digitalWrite(STEP5, LOW);
    digitalWrite(STEP6, LOW);
    digitalWrite(STEP7, LOW);
    digitalWrite(STEP8, LOW);      
  }
 if (led == 15)
  {
    digitalWrite(STEP1, LOW);
    digitalWrite(STEP2, HIGH);
    digitalWrite(STEP3, LOW);
     digitalWrite(STEP4, LOW);
     digitalWrite(STEP5, LOW);
     digitalWrite(STEP6, LOW);
     digitalWrite(STEP7, LOW);
     digitalWrite(STEP8, LOW);
         }
 if (led == 14)
  {
    digitalWrite(STEP1, LOW);
    digitalWrite(STEP2, LOW);
    digitalWrite(STEP3, HIGH);
     digitalWrite(STEP4, LOW);
     digitalWrite(STEP5, LOW);
     digitalWrite(STEP6, LOW);
     digitalWrite(STEP7, LOW);
     digitalWrite(STEP8, LOW);

  
  } 
 if (led == 13)
  {
    digitalWrite(STEP1, LOW);
    digitalWrite(STEP2, LOW);
    digitalWrite(STEP3, LOW);
     digitalWrite(STEP4, HIGH);
     digitalWrite(STEP5, LOW);
     digitalWrite(STEP6, LOW);
     digitalWrite(STEP7, LOW);
     digitalWrite(STEP8, LOW);

  } 
   if (led == 12)
  {
    digitalWrite(STEP1, LOW);
    digitalWrite(STEP2, LOW);
    digitalWrite(STEP3, LOW);
     digitalWrite(STEP4, LOW);
     digitalWrite(STEP5, HIGH);
     digitalWrite(STEP6, LOW);
     digitalWrite(STEP7, LOW);
     digitalWrite(STEP8, LOW);

  } 
   if (led == 11)
  {
    digitalWrite(STEP1, LOW);
    digitalWrite(STEP2, LOW);
    digitalWrite(STEP3, LOW);
     digitalWrite(STEP4, LOW);
     digitalWrite(STEP5, LOW);
     digitalWrite(STEP6, HIGH);
     digitalWrite(STEP7, LOW);
     digitalWrite(STEP8, LOW);

  } 
     if (led == 10)
  {
    digitalWrite(STEP1, LOW);
    digitalWrite(STEP2, LOW);
    digitalWrite(STEP3, LOW);
     digitalWrite(STEP4, LOW);
     digitalWrite(STEP5, LOW);
     digitalWrite(STEP6, LOW);
     digitalWrite(STEP7, HIGH);
     digitalWrite(STEP8, LOW);

  } 
       if (led == 9)
  {
    digitalWrite(STEP1, LOW);
    digitalWrite(STEP2, LOW);
    digitalWrite(STEP3, LOW);
     digitalWrite(STEP4, LOW);
     digitalWrite(STEP5, LOW);
     digitalWrite(STEP6, LOW);
     digitalWrite(STEP7, LOW);
     digitalWrite(STEP8, HIGH);

  } 
   if (led == 8)
  {
    digitalWrite(STEP1, LOW);
    digitalWrite(STEP2, LOW);
    digitalWrite(STEP3, LOW);
     digitalWrite(STEP4, LOW);
     digitalWrite(STEP5, LOW);
     digitalWrite(STEP6, LOW);
     digitalWrite(STEP7, LOW);
     digitalWrite(STEP8, LOW);

  } 

}

How are the inputs such as pin 12 wired ?
Do you have any pulldown resistors on them keeping them in a known state at all times when the buttons are not pressed ?

I am making no comment about the quality of the code (actually, I suppose that I just did)

:slight_smile:
thx for reply

yes the code is a bit punky, like "LookMumNoComputer" is :stuck_out_tongue_closed_eyes:
but he´s been demonstrating that it works and this is the only thing that matters for me.

as i know he´s using plenty of diodes and pulldowns which can be left by flipping internally to "PULLUP",
but this ain´t the problem here as it seems.

i´ve put a pulldown R on every of those forwarding and resetting inputs, no change.
i´m feeding "FORWARDS" with a momentary tactile button from 5V output pin.
what should work as external clock input at the end.

if i put a "HIGH" on D13 the internal LED lights on, but nothing happens, i also tried to flip the functions of the pins and slimming the code to only the "FORWARDS" function.

it stands on STEP1 and i can push the buttons, the corresponding LED/STEP lights on, but no forwarding steps

Hi Andrew_mcloud,

the most basic technique to debug errors in your code is to add debug-output to the serial monitor
to make visible what if-conditions are true and what values variables do have.
This will guide you to the place where something is wrong.

As this is a small program that just switches Outputs on/off the loop runs through thousands of times per second.
For the serial-output it must be slowed down so you can read what is written to the screen.

This slowing down is the only reason and the only senseful case to use the command delay(). (1)

Naming variables val1. val2 etc. is a ver bad coding style. It forces the reader to do extra-thinking
val1 means "button for forward counting" val2 means "..." etc.

every variable and every function should have a selfexplaining name. So I renamed the variables
in that style

Are you usingthe exact same board as LOOKMUNNOCOMPUTER.
On a Arduino-UNO-board PIN13 is connected to the Onboard-LED

Without a pulldown-resistor the onboard-LED lights up and you will get input=HIGH

If pins are configured as input you must add pullup or pulldown-resistors for reliable function.
Without pullup or pulldown-resistors even a two inch short wire can catch up enough electromagnetic noise to
make the input-pin switch randomly between high and low.

read https://www.arduino.cc/en/Tutorial/DigitalPins

You can use pinmode INPUT_PULLUP but this will invert the logic of the buttons.
If the button is not pressed the internal pull-up-resistor will "do what its name says pulling-up-voltage to HIGH"
This means the button has to make a connection from input-pin to ground so that pressing the button "pulls down the input-pin to LOW.

As the delay is one second the loop os slowed down to execute the commands only once a second.
This means you have to press and hold down any button for more than one second to make sure the button-press is detected by the code.

If you want to read the debugoutput uncheck the autoscroll-checkbox in the serial-monitor-window
(lower left corner)

So here is the code with full debugout-put renamed and well formatted code.
F***! forum-error more than 9000 characters.

OK I add the sketch as INO and as a zip-file

best regards

Stefan

(1)
In 99% of all other cases where delay can be used but the command delay()will cause trouble sooner or later.
In all these other cases you should use a programming technique known as "blink without delay"
it is not a single command it is a programming technique that needs mutliple lines of code at two places with the command "millis()"

andrew_mcloud-8-step-4017-decimal-counter-003.ino (9.82 KB)

andrew_mcloud-8-step-4017-decimal-counter-003.zip (1.74 KB)

Solved!

THX Stefan for ofering your time!

Stupid me was using the wrong R size for pulldown.

A lesson i have learned now in painful hours. :-X

I have to state, the circuit is punky aswell :stuck_out_tongue_closed_eyes:

HI Andrew_mcloud,
good if it is working now.
in your PM you wrote that the serial-output only produced glyphs. That's just the wrong baudrate
I have the habit to use 115200 baud
the number inside the command

Serial.begin(115200);

is the baudrate.
Inside the serial monitor you have to adjust the baudrate. There is dropdown button a number and then the word Baud

If you adjust the baud-rate there you should see the serial output.
I want to emphasize: my code-version is delayed you have to press the button longer than one second to make sure the button-press is detected.
If you delete the command

delay(1000);

it is running fast again but still sending all that serial-output. If there is too fast too much serial-output this can make your PC act strange. Recently I had this case.

With a more advanced code-version that uses compiler-if-conditions it is possible to switch on/off inserting the serial-debug-commands.

So I'm interested what were the values of the pull-down-resistors that you were using first?

Do you have a digital multimeter? If you are tinkering with electronics a digital multimeter is the minimum measurement equipement you should have.
I recommend this one

very good compromise between price, perfomance and possabilities. It has even bluetooth so you could record measurements on a IOS or android-app

You could have shortened your "painful hours" down to one hour through adding serial output and analysing the serial output

best regards Stefan