Blinking LED without success

Once again I apologize.
I need the pins to turn HIGH and LOW one by one in a given sequence. This is necessary to open transistors in a certain sequence. I set this sequence into the void loop and used the delay. For control, I added pin13 with LED in one line. But LED burns constantly, regardless of the delay value. I don't understand what is the problem !

int  U ; 
int timeout; 

void setup() {
 Serial.begin(9600);
pinMode(3, OUTPUT);pinMode(5, OUTPUT); pinMode(6, OUTPUT);pinMode(9, OUTPUT); pinMode(10, OUTPUT);pinMode(11, OUTPUT); 
 
pinMode(0, INPUT_PULLUP); //  hallA - pin D0 - int 2 
pinMode(1, INPUT_PULLUP); //  hallB - pin D1 - int 3
pinMode(2, INPUT_PULLUP); // hallC- pin D2 - int  1

digitalWrite(3, LOW); digitalWrite(5, LOW); digitalWrite(6, LOW); digitalWrite(9, LOW); digitalWrite(10, LOW); digitalWrite(11, LOW);

}


void loop() {
                           
U = analogRead(A0);// read the potentiometer that adjust PWM 
U = constrain(U,10,1023) ;
timeout = (1*10000/U+100);


Serial.print("U= "); Serial.print(U); Serial.print(" ");
Serial.print("timeout= "); Serial.print(timeout); Serial.println(" ");
 

// A-, B+ 
digitalWrite(9, HIGH); // (A-)=pin9, transistor М4 
digitalWrite(10, HIGH); // (B+)=pin10, transistor М5
digitalWrite(13, HIGH); // to control frequency
delay (timeout);
digitalWrite(9, LOW); digitalWrite(10, LOW);
delay (timeout);


// B+, C- 
digitalWrite(10, HIGH); // (B+)=pin10, transistor М5
digitalWrite(11, HIGH); // (C-)=pin11, transistor М6

delay (timeout);
digitalWrite(10, LOW); digitalWrite(11, LOW);
delay (timeout);



// A+, C-
digitalWrite(3, HIGH); // (A+)=pin3, transistor М1
digitalWrite(11, HIGH); // (C-)=pin11, transistor М6
delay (timeout);
digitalWrite(3, LOW); digitalWrite(11, LOW);
 delay (timeout);

 // A+, B- 
 digitalWrite(3, HIGH); // (A+)=pin3, transistor М1
digitalWrite(5, HIGH); // (B-)=pin5, transistor М2  
delay (timeout);
digitalWrite(3, LOW); digitalWrite(5, LOW);
  delay (timeout);


 // C+, B-
 digitalWrite(6, HIGH); // (C+)=pin6, transistor М3
digitalWrite(5, HIGH); // (B-)=pin5, transistor М2  
delay (timeout);
digitalWrite(6, LOW); digitalWrite(5, LOW);
delay (timeout);

  // A-, C+
   digitalWrite(9, HIGH); // (A-)=pin9, transistor М4
 digitalWrite(6, HIGH); // (C+)= pin6, transistor М3
delay (timeout);
digitalWrite(9, LOW); digitalWrite(6, LOW);
delay (timeout);
}


It seems your delay is very short, you just not able to notice how it blinks.

What timeout values do you seen in that output?

Which Arduino are you using?

Your task is a classical target for a state machine approach. SO you should consider using a switch-case structure as in this example

what is that horrible picture?

No. Maximum is more 1000ms

I assume you want LED on 13 to mimic the changes - except the code you posted never takes pin 13 LOW - so it won't do what you want it to...

Or am I missing something?

gaztech

You are genius!!!

Hi, @leon1976

Have you built this project or is it just in a sum?

To make your circuit clearer you need to use proper schematic symbols for the components, especially the transistors.
The diag does not identify the E, B, C connections.
Using LEDs as base current limiters is not advised either, you are in danger of overloading the UNO output pins.

Thanks.. Tom.. :smiley: :+1: :coffee: :australia:

I use Leonardo.
Sorry, I cannot understand how to use enum in my case.

you need to define the states the system will be in and how they will change.

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