Help Coding

All,

I hope I'm posting this in the most appropriate section.
I am new to Arduino and coding has always been very difficult for my brain to truly understand.
I am coming to the Arduino community for some assistance on building the code for my project.
I already have the timer function working and another incrementing button push function working separately. I have not been able to combine the two.
If some coding savy arduino expert out there reads this and could slowly guide me through the coding process, I would greatly appreciate it.
Let me know if I am leaving out some huge information. Please understand that I am a total beginner in this area.

Thanks,
Steve

-See Below

Goal:
build a push button lap timer with 4 different modes.

Materials:
Arduino Uno
Green 4-digit 7-segment display w/ backpack
Red 4-digit 7-segment display w/ backpack
Push buttons
Resistors
digital Potentiometer

Pseudo Code:

MODE 1 (Distance MODE)
Select mode 1 with the scrolling wheel
LED lights up next to a sticker that says "laps"
hit the button, the timer starts
Green 7 segment display shows lap number
Red 7 segment display shows time
Swim first lap
hit the button to finish the lap
green 7 segment display shows lap 1
red display flashes the lap time for 2 seconds
lap number and time are recorded while continuing to count total time
Swim second lap
hit the button to finish the lap
green 7 segment display show lap number 2
red display flashes the lap time for 2 seconds
lap number and time are recorded while continuing to count total time

so on and so forth for at bare minimum of 50 laps.

Come home, plug it in to computer to upload all of the times and laps.

MODE 2 (Countdown MODE)
Select mode 3 with the scrolling wheel
LED lights up next to a sticker that says "countdown timer"
use the digital potentiometer wheel to select the length of time you want to swim on the red 7 segment.
hit the start button
timer starts on red display
every time you complete a lap, hit the start button and the lap number shows on green display
timer continuously counts total time
the arduino stores all laps and split times.
when the timer reaches zero the red 7 segment flashes 8888 until you hit start.

MODE 3 (Lap Record MODE)
Select mode 3 with the scrolling wheel
LED lights up next to a sticker that says "countdown laps"
use the digital potentiometer wheel to select the number of laps you want to swim (50 laps) on green 7 segment
an led lights up next to a sticker that says "time to beat" (lets us 0:30 as an example)
use the scrolling wheel to select the goal time
hit the button to start
begin swimming laps
if your lap is faster than 0:30, then a small green LED flashes for a few seconds
if your lap is slower than 0:30, then a small red LED flashes for a few seconds

the arduino records all times in memory for uploading to home computer.

MODE 4 (Stroke Efficiency Calculator)
Select mode 4 with the scrolling wheel
LED lights up next to a sticker that says "SWOLF"
select the number of laps you want to track (lets say 50 for this example)
hit the start button
start swimming your lap
count the number of swimming strokes in your head
hit the start button once you return
the timer stops
LED lights up next to a sticker that says "number of strokes"
use the scrolling wheel to select the number of strokes it took you to swim one lap
LED lights up next to a sticker that says "difficulty level"
use the scrolling wheel to select the difficulty out of 10.
hit the start button and a simple math calculation runs (strokes plus time)
the next lap starts when you hit the start button.
repeat for 50 laps

the arduino records all times in memory for uploading to home computer.

Please:

Always show us your ‘current’ compete sketch.
Use CTRL T to format the sketch.
Please use code tags.
Use the </> icon in the posting menu.

[code] Paste sketch here. [/code]

.

Show us a good schematic of your circuit.
Show us a good image of your wiring.

If this is your first project, you are ambitious. At least, you have defined your tasks much better than most beginners. It's more a problem definition than pseudocode, as it contains things that the computer doesn't do, like "swimming a lap". It would be good as a next step to frame it completely from the point of view of the computer, as in "wait for signal that a lap has been completed", or some such.

Thanks for the advice guys. I am working on drawing up a digital version of what I have in Fritzing and will get that posted here so you know what I am talking about. I will also try to upload some pictures of what I have. This is a very new process for me so thank you in advance for your patience.

I re did the pseudo code. How does this look? Any gaping holes?
I think I am going to try and do only one function now and add more as I learn more

Code:

MODE 1 (Distance MODE)
turn device on
return 'high' from 'button 1' to start lap timer
Green 7 segment display show "L 0"
Red 7 segment show lap time
while total time continues to count in background

return 'high' from 'button 1' for less than 2 seconds to increment Green 7 segment display (finish first swimming lap)
write lap number and lap time to 'memory slot 1'
green 7 segment display show "L 1"
red 7 segment display show lap time from 'memory slot 1' for 2 seconds
while continuing to count current lap and total time in background.

return 'high' from 'button 1' for less than 2 seconds to increment Green 7 segment display (finish first swimming lap)
write lap number and lap time to 'memory slot 2'
green 7 segment display show "L 2"
red 7 segment display show lap time from 'memory slot 2' for 2 seconds
while continuing to count current lap and total time in background.

Loop for at least 50 laps.

(Lets say I only swam 2 laps)

return 'high' from 'button 1' for more than 2 seconds to break out of loop and stop all timers
green 7 segment display show "L 2"
Red 7 segment display show "1:01" (total time)
return 'high' from 'button 1' for less than 2 seconds
green 7 segment display show "L 1"
Red 7 segment display recall 'memory slot 1' (0:30) (Lap 1 time)
return 'high' from 'button 1' for less than 2 seconds
green 7 segment display show "L 2"
Red 7 segment display recall 'memory slot 2' (0:31) (Lap 2 time)

return 'high' from 'button 1' for more than 4 seconds to clear all memory slots

Turn device off
Come home, plug it in to computer to upload .txt file of all times and laps.

flahertysan:
I think I am going to try and do only one function now and add more as I learn more

Very wise.

Build your program in very small steps, testing at each stage. For example write short little programs to read a button or display a digit on a 7 segment display. Don't try to build a composite program until you can do each part on its own.

...R
Planning and Implementing a Program

flahertysan:
I am working on drawing up a digital version of what I have in Fritzing and will get that posted here so you know what I am talking about.

Don't, Fritzing is almost universally reviled as sloppy and inappropriate to properly representing a circuit. Pick up a piece of paper and pencil and use that instead (or a drawing program if you really can't stand paper).

Robin2:
Very wise.

Build your program in very small steps, testing at each stage. For example write short little programs to read a button or display a digit on a 7 segment display. Don't try to build a composite program until you can do each part on its own.

...R
Planning and Implementing a Program

I already learned how to Increment button pushes and got that working. See below
I already learned how to start and stop a timer and got that working. See below

Code for incrementing button pushes:

#include <Wire.h> // Enable this line if using Arduino Uno, Mega, etc.
#include "Adafruit_LEDBackpack.h"

Adafruit_7segment matrix = Adafruit_7segment();

int buttonState = 0;
int lastButtonState = 0;
int buttonPushCounter = 0;

void setup()
{
 pinMode(2, INPUT);
 pinMode(13, OUTPUT);  
 Serial.begin(9600);
 matrix.begin(0x70);

}

void loop()
{
 buttonState = digitalRead(2);
 if (buttonState != lastButtonState) 
 {
   if (buttonState == HIGH) 
   {
     buttonPushCounter += 1;
     matrix.print(buttonPushCounter);
     matrix.writeDisplay();
   }
   delay(5); // Wait for 5 millisecond(s)
 }

Code for timer:

#include <Wire.h> // Enable this line if using Arduino Uno, Mega, etc.
#include "Adafruit_LEDBackpack.h"

Adafruit_7segment matrix = Adafruit_7segment();

void setup() 
{
 Serial.begin(9600);
 matrix.begin(0x70);
}

void loop() 
{
 //count minutes and seconds up to 99 minutes and 60 seconds.
 for (uint16_t counter = 0; counter < 6000; counter ++)
 {
   matrix.writeDigitNum(0, (counter / 600));
   matrix.writeDigitNum(1, (counter / 60) % 10);
   matrix.drawColon(true);
   matrix.writeDigitNum(3, (counter / 10) % 6);
   matrix.writeDigitNum(4, counter % 10);
   matrix.writeDisplay();
   delay(1000);
 }
}

As requested in reply #1...

Please use code tags (</> button on the toolbar) when you post code or warning/error messages. The reason is that the forum software can interpret parts of your code as markup, leading to confusion, wasted time, and a reduced chance for you to get help with your problem. This will also make it easier to read your code and to copy it to the IDE or editor. Using code tags and other important information is explained in the How to use this forum post. Please read it.

I think the mode/value selection "wheel" you are referring to is probably a rotary encoder. Nice ergonomic addition to your project, but you should add getting encoder and getting it to work to your list of sub projects.

You also mention data logging. You should add getting an SD card reader or compatible USB shield working to your list as well.

Not a beginner project, but it has a lot of very basic components that are well supported. Stick with it and you will certainly learn a lot and should have a nice tool to show for it.