Making/made turn signal program

So this is my first post, so formal introduction, my name is Tony, I'm a junior at Purdue. I built an electric motorcycle, starting from just the frame. I'm (attempting) to use an Arduino for the turn signals. Pretty simple plan, I'll give the turn signal switch +5V, have two pins (left and right ) as digital inputs and then two digital outputs to MOSFETs to blink them. Figured it'd be simple....... it never is. I'm hoping this is one of those times where the author stares at code for hours and can't figure it out and the next person, at first glance, figures it out. Here's the code, I commented the crap out of it:

// Turn Signal Program

#define Left 13 // This pin is assigned to turn on the left turnsignal
#define Right 12 // This pin is assigned to turn on the right turnsignal
#define Leftin 8 // This is a 5V input pin for the left side
#define Rightin 4 // This is a 5V input pin for the right side

int valleft = 0; // Stores the state of the left input pin
int valright = 0; // Stores the state of the right input pin
int t = 500

void setup() {
pinMode(Left, OUTPUT); // This sets the left pin 13 as an output
pinMode(Right, OUTPUT); // This sets the right pin 12 as an output
pinMode(Leftin, INPUT); // This sets the leftin pin 8 as an input
pinMode(Rightin, INPUT); // This sets the rightin pin 7 as an input
}

void loop() {
{
val = digitalRead(Leftin); // Reads the leftin value and stores it
// check is the input is HIGH
if (valleft == HIGH) {
digitalWrite(Left, HIGH); // turns left turn signal on
delay(t);
digitalWrite(Left, LOW);
delay(t);
}
else {
digitalWrite(Left, LOW);
}
}
{
val = digitalRead(Rightin); // Reads the leftin value and stores it
// check is the input is HIGH
if (valright == HIGH) {
digitalWrite(Right, HIGH); // turns left turn signal on
delay(t);
digitalWrite(Right, LOW);
delay(t);
}
else {
digitalWrite(Right, LOW);
}
}
}

My error is "error: expected unqualified-id before numeric constant In function 'void loop()':" and it highlights line 6; "#define Rightin 4 // This is a 5V input pin for the right side" Any help would be greatly appreciated, I can't see anything wrong with it....unless....can I do two loops like that? I've never needed two separate loops, as embarrassing as this sounds, this is the most complicated Arduino program I've written. Thanks in advance, I can't figure it out.

That's about right, I press post and, instantly, the lack of a ";" after "int t = 500" jumps out at me. After re-verifying, I change "val" into "valleft" and "valright". Thanks for all the help! I guess my question remains, can I do two loops like this? I'm thinking it will just keep cycling through the first loop. I guess I could take 45 seconds and just go test it, but I feel like I need to ask something or I'll feel like a spammer on my first post.

You could make "t" const as its value is never changed.
"val" is never declared. It also seems un-necessary to store the value of the input pin if all you are going to do with is test the value once. Just use

if (digitalRead(Leftin) == HIGH) {

(the #-button among the editing tools can be used to mark sections of a post as code.)

Hi Tony,
Awesome project to hang your Arduino on! You MUST include a description and pics of the bike!

Rather than using Delays, I would suggest that you read and understand this tutorial.

On to the turn signals. It looks to me like you expect the turn switch to remain high for the duration that the rider wants the signal on. This requires the rider to remember to cancel the signal each time.

I would propose a different user interface.
Use momentary switches.
Momentarily pressing either one starts the blinking.
The blinking continues until both of 2 events occurs.

  1. A certain time has elapsed.
  2. A certain distance has been traveled.

This is the UI that my GoldWing uses.
It actually has a third momentary switch that cancels the turn signal. The switch can be pushed to the left or right, and when it is in the middle, if you press IN it cancels the turn signal. Pressing the turn signal restarts the turn timer and distance calculation.

This UI means works very well for traveling on real roads, and has been tested on a zillion GoldWings. It keeps the signal on the entire time you are sitting in the left turn lane waiting for a long light. It keeps the signal on for a reasonable time on the highway for a lane change.

I think that the parameters are something like 7 seconds and 800 feet.

Or, you could go with the UI that my brother's Harley has.
Momentary switch on each handlebar. Pressing once turns on that turn signal. It is on until you press that switch again, or if you press the other switch which turns that turn signal on.

I'm using the same turn signal switches as your Goldwing. Left and right and then push in the center to cancel.

This looks water-proof to you, right? :wink:

Ended up just using a 555 timer. MUCH easier. I'll be saving my Arduino for something even more fun on the motorcycle. ;D Vinceherman, here's a short video I made of the design/build/test process on the bike: