Programming Problem with pwm and millis

Dear James,

i want to make the arduino sketch to work with Millis but i try it many time and it will not work.

But there is a second problem, i press button it count 1 and my output c1 is coming 2 times ?

If you can help me to resolve my problem,( i think thath is 2 minutes off work for you) and for me it is a mountain.( i am new worker with arduino)

I added the 2 Sketch

Sorry for my english i am a frenchie.

Regards,

Thierry

canon10A.ino (1.58 KB)

canon10B.ino (2.48 KB)

Please use the auto-format tool to indent your code consistently - it makes it very much easier to read.

I think the problem is in the way you update the variable count. It was fine when you were using delay() because everything was on hold while the delay()s did their thing.

But for the timing with millis() to be able to work it is essential that loop() can repeat hundreds of times. My wild guess is that the variable count is changing before the interval expires.

Have a look at how millis() is used to manage timing in Several things at a time. And note how putting the code into small functions makes it much easier to manage.

...R

there is a french forum... where it will be easier to get help if english is a challenge

Thanks Robbin,

but if i use the delay fonction i have count1 with "c1" who is coming for 2 time, i did not understand Why?

thierrymuller:
but if i use the delay fonction i have count1 with "c1" who is coming for 2 time, i did not understand Why?

I only glanced briefly at your first program to get a sense of what the 2nd program is trying to achieve. I presume the 2nd program is the important one.

Break it down into small parts and get each piece to work separately before trying it all together.

...R
Planning and Implementing a Program

how are things wired? do you use a pulldown on the button? how do you handle bouncing?

this feels weird, pinMode should take INPUT, OUTPUT or INPUT_PULLUP, not LOW...

  pinMode(c1, LOW);
  pinMode(c2, LOW);

why do you take the time to declare const int buttonA = 2;and then do   UpState = digitalRead(2); you should use buttonA instead of 2...

indeed with all the delays you don't read your button very often

I'd recommend you implement a state machine - you can read a small tutorial in french here

merci
je vais lire le sujet state machine
je veu contoler 2 mos-fet en pwm car le tout alimenter par une batterie 12volt

thierrymuller:
merci
je vais lire le sujet state machine
je veu contoler 2 mos-fet en pwm car le tout alimenter par une batterie 12volt

If you wish to use French please go to the French section of the Forum. This is the English language section.

...R