Arduino code 'Cycle' problem

Hello friends, I want to add a feature to this code. When a button connected to the D2 pin is pressed, a scanning mode is activated and when the button is pressed again, I want it to stop. When the scanning mode is active, I want the buttons defined between M1-M6 in the code to cycle at one second intervals. I tried a lot but I was not successful. Can anyone help?
Tracer v3.txt (12.0 KB)
Tracer v3.txt (12.0 KB)

Please post the code here to avoid the need to download it. Please use code tags when you do

In my experience the easiest way to tidy up the code and add the code tags is as follows

Start by tidying up your code by using Tools/Auto Format in the IDE to make it easier to read. Then use Edit/Copy for Forum and paste what was copied in a new reply. Code tags will have been added to the code to make it easy to read in the forum thus making it easier to provide help.

1 Like

Many of the pins in your code are not configured. Post your formatted code.

Posting an annotated schematic showing exactly how this is wired will help us help you. Be sure to show all connections, power, ground and any other hardware items connected to the project. Show power sources as well.

can you first describibe what you 496 line program is intended todo?

how do you "cycle" a button?

looks like the code is manipulating a large # of pins and using several digital Potentiometers

code could probably be much smaller using arrays and/or tables descibing parameters for each pin: 6-13, 22-45

That's an understatement. Functions wouldn't hurt either, viz:

// set a digital potentiometer at pin thePin to value
void MCP41010Write(byte thePin, byte value)
{
  digitalWrite(thePin, LOW);
  SPI.transfer(B00010001); 
  SPI.transfer(value);
  digitalWrite(thePin, HIGH);
}

Also it looks like handling the six whatever they ares as corresponding bits in a variable or two would make further the collapse of this sketch.

a7

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.