How to program input switch??

Hellow everyone, i have been working on a little project of mine, i want to make some cop lights for my 99 honda civic, so far this is what i got

so now that i got the actual physical connections down i need the programing part,

i know how to modify the blink command to make it blink is a certin patter such of a cop light patter,

but i want to add 5 input buttons, 1 for 0ff and the other 4 for 4 different light pattern,but i dont know how the programing would look like or be for 5 button input with 4 diff lgiht pattern,

could anyone body help me out, sorta pointing me to the right direction on where i can learn or maybe if you guys could explain.

thanks for the help everyone :smiley:

I usually program my sketch like this:

define setup code
baudrate
pullup / pulldown resistors
debug ?
define pins
declare pin numbers

setup() - pinModes and maybe pullup resistors , and/or serial communication

loop()
get current states
do logic based on the current states
execute based on the current states

[edit]I've actually made a sketch that works, but did not post it in case you want to try for yourself first. Let me know if you want to see it. I'll gladly post.[/edit]

yea that would b great, do u also know where i can learn to code inputs. The way that I want it by puting 5 inputs, 1 for off and the other 4 inputs make 4 diff light patterns

Enjoy :slight_smile:

This should print to the console what the current status is:

/*
|| A police light imitator
|| One control the lights using five switches. One light on/off switch, and four mode switches or state swithes.
|| This will give the user the oppertunity to choose between four animations/patterns/modes and also to shut it off, or turn it on.
||
|| Contributed:
|| Alexander Brevig
*/

//setup code
#define DEBUG 1 //0 if serial debugging is to be turned off
#define PULLUP 1 //0 if pulldown resistors are used
#define SWITCH_PRESSED (!PULLUP)

//define states
#define LIGHT_STATE_1 0
#define LIGHT_STATE_2 1
#define LIGHT_STATE_3 2
#define LIGHT_STATE_4 3

//variables
#define LIGHT_ON_SWITCH 0 //array index 0 == pin 8, will be the on/off switch for the lights
#define NUMBER_OF_PINS 5
byte switchPin[NUMBER_OF_PINS] = { 8 , 9 , 10 , 11 , 12 }; //8 is on/off switch, 9-12 will be control switches
boolean switchValues[NUMBER_OF_PINS] = { 0 , 0 , 0 , 0 , 0 };

byte currentState = LIGHT_STATE_1;

void setup() {
//configure all switchPins as INPUT
for (byte i=0; i<NUMBER_OF_PINS; i++){
pinMode(switchPin*,INPUT);*

  • if (PULLUP){*
  • //if the internal pullup resistor is to be used, turn it on*
    _ digitalWrite(switchPin*,HIGH);_
    _
    }_
    _
    }_
    _
    if (DEBUG) { Serial.begin(9600); }_
    _
    }_
    void loop(){
    _
    //set all states*_
    * for (byte i=0; i<NUMBER_OF_PINS; i++){
    if (digitalRead(switchPin)==SWITCH_PRESSED){
    _ switchValues=true;
    }else{
    switchValues=false;
    }
    }*_

* //if lighs are on*
* if (switchValues[LIGHT_ON_SWITCH]){
_ //do logic*
* for (byte i=1; i<NUMBER_OF_PINS; i++){*
if (switchValues*){
currentState = i;
switchValues = false; //this state is now acted upon, flush it.
}
}
//execute current state*

* switch (currentState){_
case LIGHT_STATE_1: lightState1(); break;
case LIGHT_STATE_2: lightState2(); break;
case LIGHT_STATE_3: lightState3(); break;
case LIGHT_STATE_4: lightState4(); break;
_ }
}else{//if light are to be shut off, do so:
lightsOff();
}
}
void lightState1(){
//TODO - implement pattern 1*

* if (DEBUG) { Serial.println("lightState1"); }
}
void lightState2(){
//TODO - implement pattern 2*

* if (DEBUG) { Serial.println("lightState2"); }
}
void lightState3(){
//TODO - implement pattern 3*

* if (DEBUG) { Serial.println("lightState3"); }
}
void lightState4(){
//TODO - implement pattern 4*

* if (DEBUG) { Serial.println("lightState4"); }
}
void lightsOff(){
//TODO - implement lightsOff*

* if (DEBUG) { Serial.println("lightsOff"); }
}
[/quote]*_

wow man,where did u learn that stuff man, is there a tutorial for this because if love to learn it,

it looks very complex at first but anything is learnable right

but with this code it would do what i want right n id just have to put in the light patter that id want correct

thanks alot man for ur help

Take a look at this:
Arduino Reference
#define
arrays[]
for
if...else
switch case

Although my code maybe look complex, it is actually basen on a few simple keywords an a set of syntax rules. Eventually you will see what lies behind all the wierd symbols. :slight_smile:

Happy Coding!

I'm new myself, but I might be able to help. I just uploaded information about my first program which is a light sequencer for my car, and it allows for multiple sequences

http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1238659623

I haven't put in the transistors or voltage regulators, but it looks like we are trying to do about the same thing.

irvinds,
You do know that the circuit you posted will only switch all the LEDs on or off at the same time so the only pattern you can get with this is a pattern of blinking.
Or are there more LED groups and transistors?

:Dyea this is just an example i drew up but in fact theres going to be more npn's n more resistors,

i would like to do 2 for my front grill and 2 sets for my rear window

so it would b about 4 npn's and i dont even know how many leds per set but about 20-30 leds

Not to be a wet blanket, but you do realize that in many states (NY included) it's illegal to have red or blue lights even if they are not illuminated.

oh i agree with you %100,but i checkd the status n it claims that its illiagl to have the lights on wail the car is runiing on the road, but u can have them ligally on ur vehical when the car is not running n when ur off roads,there pefectly fine,

I also had a buddy of mine confirm it because he does a lot of stupid stuff to hiis car n he sayd he been alright,infact once he claims that he had the lights on wail an officer passed him and they didn't say anything,

But what do you guys think on the topic