New to programming. I have a input question.

Hello, I am working on my first project and I hit a road block. I am trying to use an input for two functions. One is HIGH the second is a pulse "on off on" I need the input to run two different outputs.

I tried using a pulseIn. I'll post the code if I can log in from my pc. I have been having trouble logging in to this form. I am on my phone now. Any input would be appreciated

It sounds like you have two outputs connected to one input. This is usually a BAD idea.

You need to provide more information: Voltage levels, timing information, output impedances, etc.
Please also explain more about what Arduino you have.

You may be able to use resistors to create different levels and to sum the outputs and then read them with an analog input.

It is hard to answer a question that has not been asked.

pulseIn works from a digital input, but that may not be what you have, although I admit that I am quite confused about what actually takes place in your project.

I am trying to use an input for two functions. One is high the second is a pulse. I need the input to run two different outputs.

So, you need one output pin to go HIGH and stay there, and another output pin to go HIGH for - say - 5ms.

To put it another way, you want one output to go HIGH on your input and to go LOW when the input is no longer true, and you need the other output to go HIGH and to go LOW 5ms after it went HIGH.

the usual way to do this is:

unsigned long markMs;
byte state = HIGH;
boolean inPulse = false;

loop() {
  byte prevState = state;
  state = digitalRead(pushbuttonPin);
  if(state == LOW && prevState == HIGH)  {
    // button has just been pressed
    digitalWrite(output1Pin, HIGH);
    digitalWrite(output2Pin, HIGH);
    markMs = millis();
    inPulse = true;
  }
  else if(state == HIGH && prevState == LOW)  {
    // button has just been released
    digitalWrite(output1Pin, LOW);
    digitalWrite(output2Pin, LOW);
  }
  else if(state == LOW) {
    // button is being held down
    if(inPulse && millis()-markMs >= 5) {
      digitalWrite(output2Pin, LOW);
      inPulse = false;
    }
  }

}

Ok I am going to break this up. Sorry for posting a bunch. First thank for the replies, I appreciate them.

What am I trying to do? I have two inputs and two outputs.
If input one is Low and input two is Low then output on and two are high.

If input one is pulsing and input two is low then output one blinks and output two is high.

If input two pulses and input one is Low then output two blinks and output one is high.

If input one and two are high outputs off.

Inputs are pulled up. Next post I'll answer some of your questions

As far as inputs go I am just using push buttons. The voltage is +5v from the Arduino. I have added a hardware debounce to both inputs 1k ohm pull-up resistor and a 10uF cap to ground. I am going to add a 74c14 "Schmitt trigger" to the circut when it gets here. It's in the mail.

As for the outputs I have a couple of transistors isolating the outputs. I am just powering two leds. I am using a +9v batt to power them.

I have an Arduino uno.

int inputOne = 2; //set input one as pin two
int inputTwo = 3; //set input two as pin three
int inputThree = 4; //set input three as pin four

int outputOne = 9; //set output one as pin nine
int outputTwo = 10; //set output two as pin ten
int outputThree = 11; //set output three as pin eleven

int brightness = 150; //set led brightness
int maxBrightness = 250; //set led max brightness
int setDelayOne = 100; //set delay one
int setDelayTwo = 200; //set delay two

unsigned long pulseInOne = 0; //space for pulse lenght
unsigned long pulseInTwo =0; //space for pules lenght two
int inThreeState;
int debug = 1; // 1 to run serial print 0 off

void setup() {
  // put your setup code here, to run once:
Serial.begin (9600);
pinMode (inputOne, INPUT_PULLUP);//set pin 2 as input pullup
pinMode (inputTwo, INPUT_PULLUP); // set pin 3 as input pullup
pinMode (inputThree, INPUT_PULLUP); //set pin 4 as input pullup
pinMode (outputOne, OUTPUT); //set pin 9 as output
pinMode (outputTwo,OUTPUT); //set pin 10 as output
pinMode (outputThree,OUTPUT); //set pin 11 as output


}

void loop() {
  // put your main code here, to run repeatedly:
pulseInOne = pulseIn (inputOne,LOW); //read pulse on input one
pulseInTwo = pulseIn (inputTwo,LOW); //read pulse on input two
inThreeState = digitalRead (inputThree); //read state of input three

if (debug=1){
Serial.print ("input one ");
Serial.print (pulseInOne);
Serial.print (" , ");
Serial.print ("input two ");
Serial.println (pulseInTwo);
}

if ( pulseInOne <= 30000 && pulseInTwo >= 40000 ){ //blink out one and out two low if in one pulse and in two high
  digitalWrite (outputTwo, HIGH);
  digitalWrite (outputOne, HIGH);
  delay (setDelayOne);
  digitalWrite (outputOne,LOW);
  delay (setDelayTwo);
}else{
  digitalWrite (outputOne,LOW);
  digitalWrite (outputTwo,LOW);
}


if (pulseInTwo <= 30000 && pulseInOne >= 40000){ //blink out two out one low if pulse on in two and in one high
  digitalWrite (outputOne,HIGH);
  digitalWrite (outputTwo, HIGH);
  delay (setDelayOne);
  digitalWrite (outputTwo,LOW);
  delay (setDelayTwo);
}else{
  digitalWrite (outputTwo,LOW);
  digitalWrite (outputOne,LOW); 
}


if (pulseInOne >=40000 && pulseInTwo >= 40000){ //when input one and two stay low out one and two go HIGH
  digitalWrite (outputOne, HIGH);
  digitalWrite (outputTwo,HIGH);
  delay (10); //added delay so leds would be brighter 
}else{
  digitalWrite (outputOne, LOW);
  digitalWrite (outputTwo,LOW);
}
}

turbonasty:
What am I trying to do? I have two inputs and two outputs.
If input one is Low and input two is Low then output on and two are high.

If input one is pulsing and input two is low then output one blinks and output two is high.

If input two pulses and input one is Low then output two blinks and output one is high.

If input one and two are high outputs off.

Inputs are pulled up. Next post I'll answer some of your questions

Can that be simplified to this

if input N is LOW, output N is HIGH
if input N is HIGH, output N is LOW

or, in code terms

digitalWrite(outPinA, ! digitalRead(inPinA) );
digitalWrite(outPinB, ! digitalRead(inPinB) );

...R

The voltage is +5v from the Arduino. I have added a hardware debounce to both inputs 1k ohm pull-up resistor and a 10uF cap to ground.

Don't you need a pull down resistor? What is the pin state when button is NOT pressed?

Not pressed it would be high. I used input_pullup as well as a pull up on the debounce. The arduino should be looking for a Low when button is pressed.

I want to make one of these. It takes two inputs left and right turn and brake. And makes them separate. Maybe this will help explain what I want to accomplish

image1.png

Image from Reply #10 so we don’t have to download it. See this Image Guide

2f9557c7948931197732236a69a6ff610ec7f576.png

…R

Did you read Reply #6? I think what I suggested reflects what you stated.

I'm afraid I cannot make sense of the image.

...R

Thanks Robbin for reposting the pic. I didn't know how it would show up. First time posting a pic. I'll check out that link for the next pic.

As far as reply #6 I looked up the "!" I think it is called an operand, and it has an opposite effect. I'm not 100% on that one yet.

I would like the option to change the output. I was thinking it would be cool to have sequential turn signals on my trailer.

If (the part I can't figure out) {
digitalWrite (outputone,HIGH);
delay (200);
digitalWrite (outputtwo,HIGH);
delay (200);
digitalWrite (outputthree,HIGH);
delay (200);
}else{
digitalWrite (outputone,LOW);
digitalWrite (outputtwo,LOW);
digitalWrite (outputthree,LOW);
}
[\code]

I noticed the pic is hard to read. I was about to post a pic I took of the Sreial.print I did, but it can't be read either once I made the file smaller... maybe I can post the pic somewhere else and link it. The picture I posted is a break light converter. A 2 to 3 wire. Not a 3 to 2. Older cars have one wire that works the left turn and break lights. Then one that works the right turn and break lights. When you press the breaks. Both the right and left turn light up "HIGH" when you turn left the left turn lights blink. "On off on off" pulse high low high low. Same with the right. When you hit the breaks and turn. The direction you are turning blinks and the other side is steady on. The trailer is wired differently. Breaks and turn are separate circuits. After I figure out the inputs I can have the outputs do anything. I can build a matrix and have it say stop or left turn right?

P.S. I could not get the pic in the thread. Most of my posting is done from my phone. Thanks for taking the time. I appreciate that you guys are entering my questions. I don't feel like I have done a good job explaining what I am trying to do.

I don't think this posted, so im trying again.

turbonasty:
I looked up the "!" I think it is called an operand

Operator.

Just copy and paste the Serial output - don't post it as a picture. Put the output inside code tags.

As far as reply #6 I looked up the "!" I think it is called an operand, and it has an opposite effect. I'm not 100% on that one yet

I used that because earlier you said

If input one is Low and input two is Low then output on and two are high.

in other words you want the output to be the opposite of the input.

I could not see anything in your description in Reply #3 that requires logic that needs to take account of the combined state of the two pins.

I would like the option to change the output. I was thinking it would be cool to have sequential turn signals on my trailer.

All this makes me think you have not told us with sufficient clarity what you want to happen.

...R

Hello, I have been doing a lot of work, reading, googling, testing. I think I'm ready to try this again.

I am working on my first project that a buddy and I came up with. We thought it would be neat if we could make sequential led lights. I see after all the research that we weren't the only ones who thought that. I thought that should be somewhat easy to do with the Arduino I picked up. There is one problem I ran in to. I only saw it mentioned in one post, but never resolved. Most of the post I read people were just using push buttons for there inputs. I did the same thing, but I know that that's not how actual turn signals work. The turn signals pulse on and off.

I have four inputs for this project they are; 1-reverse lights +0v is off and +12 volts is on. I plan to isolate this and the other inputs with a relay. So open is off and closed will be on. I'm thinking debounce shouldn't be need here. 2 parking lights or running lights, all lights on dimmer. This is also +12 volts on. 3 left turn and 4 right turn. The left and right turn are the problem. Left turn is +12 volt, +0 volt, + 12 volt... on, off, on... the right is the same. Then break lights are left and right turn on +12volts.

I need to figure out a way to use the left and right turn inputs. I have explored pulseIn. The pulseIn from what I have read stops the program until the pulse stops, and it seems to miss the start of the pulse sometimes. So I stumbled upon interrupt pins. I think this might work better, but I have delays in my turn functions, and there are only two pins on the UNO 2&3. I am using 3 as pwm output for parking lights. After I get this working I plan on researching ways to make program neater, smaller, faster. Maybe a library. Also I am going to look in to removing the delays and using something else.

here is a video of what I have so far. trim A759A475 98EB 43FC B2DA A8BE27C0CFA6 - YouTube
here is a video of the flash to give an idea of how long the flash is trim 8125E0D5 C637 452F 9932 6DEDE0C75B4C - YouTube

That's an awful lot of code.
Why is it so big?

It's the second code I have written. I think it looks so big because of the repeated functions for turning left and write. I put notes in where I need help. Mostly the last part of the code. Once I get the last part figured out. I am going to attempt to make it smaller. I am thinking I need to do something with the flasher input where I measure the amount of pulses in a set time. To create a variable that I can use in my if statement. I'll just keep looking on line until I figure it out, but I figured I would ask for help. I haven't found anything that helps so far. I have seen some amazing things that can be done. I thought this possible.

This seems to be the same problem with almost the same title as your other Thread.

I am suggesting to the Moderator to merge them so that we have all the info in one place.

...R