I messed up somewhere (12V Switch with digispark)

Problem is that the button shows unexpected behavior.
Ok, here is what I have so far:

#define Strip 0
#define LifeLine 1
#define ReadPin 2
#define ButtonLED 3 // blau
#define PWMRANGE 255
#define jStart 50
byte i = 0;
byte j = jStart;
bool on =0;
bool pressed =0;
unsigned long millisPressed=0;

void setup()
{
  pinMode(ReadPin, INPUT);
  pinMode(ButtonLED, OUTPUT);
  pinMode(Strip, OUTPUT);
  pinMode(LifeLine, OUTPUT);
}

void loop()
{
  if (digitalRead(ReadPin) == 0) {
    if(!pressed) {
      millisPressed=millis();
      pressed =1;
    }
    // Long press activates dimming
    if ((millisPressed+500)<millis()&&(!on)){
      j=jStart;
      digitalWrite(ButtonLED, HIGH);
      while (digitalRead(ReadPin) == 0) {
        j++;
    analogWrite(Strip, j);
        delay(10);
        if (j>(PWMRANGE-1)) {
          while (digitalRead(ReadPin) == 0) {
            ledBlink();
          }
          break;}
      }
      pressed=0;
      on=1;
    }
  }
  else if (pressed) {
    pressed=0;
    if (!on) {
      digitalWrite(ButtonLED, HIGH);
      digitalWrite(Strip, HIGH);
      on =1;
    } else {
      // Longer press activates timed power off
      if ((millisPressed+1000)<millis()){
        for (byte l=0; l<(2*60); l++) {
          ledBlink();
          if (digitalRead(ReadPin) == 0) {
            break;
          }
        }
      } 
      digitalWrite(ButtonLED, LOW);
      digitalWrite(Strip, LOW);
      on =0;
      j = 0;
    }
  }
  digitalWrite(LifeLine, HIGH);
  delay(50);
  digitalWrite(LifeLine, LOW);
  delay(50);
}

// function to make the button blink
void ledBlink() {
  digitalWrite(ButtonLED, LOW);
  delay (400);
  digitalWrite(ButtonLED, HIGH);
  delay (100);
}

The simulation works fine (done on tinkercad), please ignore that I clipped the blue wire to the resistors (can't program it when this is connected, so I only can solder that once everything is final). And yes, my keyboard needs cleaning.


Hi,

Please read the post at the start of any forum , entitled "How to use this Forum".
OR
http://forum.arduino.cc/index.php/topic,148850.0.html.

It will show you how to post your images in your post.

The fact that you have put all your circuitry on the back of the DigiSpark PCB instead of on a separate blank piece makes it difficult to see your layout.

Making you project so you can plug the Digispark into the proto/vero/strip board with your other components will help debugging immensely.

Do you have a DMM?

Thanks.. Tom.. :slight_smile:

How is the input wired ?
Do you have a pullup resistor in place ?

TomGeorge:

Don't be so snarky, I don't have those images on the web. And adding those attachments takes an extra step, and I'm not that fast.

thaaat_guy:
Don't be so snarky, I don't have those images on the web. And adding those attachments takes an extra step, and I'm not that fast.

I'm not being "snarky", not intended, just pointing you to the concise "how to" of the forum to make things easier for us all.
If I was to fast I apologise.
Thanks for posting your images. Tom.. :slight_smile:

UKHeliBob:
How is the input wired ?
Do you have a pullup resistor in place ?

I have a 100k resistor between the input and 5V (accidentally put the 5V converter over that in the fritzing)

TomGeorge:
I'm not being "snarky", not intended, just pointing you to the concise "how to" of the forum to make things easier for us all.
If I was to fast I apologise.
Thanks for posting your images. Tom.. :slight_smile:

Came across a bit condescending. Would be much easier to do it right if the forum would allow to insert attachments before posting it.

thaaat_guy:
Would be much easier to do it right if the forum would allow to insert attachments before posting it.

It does, got to preview instead of post and the attachment feature appears.
Tom.... :slight_smile:

TomGeorge:
It does, got to preview instead of post and the attachment feature appears.
Tom.... :slight_smile:

No, it doesn't. (And just in case I tried it with this post ... tho I deleted the attachment to be before finalizing the post ... although my script blocker might interfered with that feature if it is a real thing)

It is the case that to attach and embed an image is a two-step process. Write a post, preview it in order to attach the file, post it, copy the attachment link then modify the post to embed the link as an image.

I almost always make the image a link as well, though clicking on it is generally the same in effect as clicking on the attachment. Due to a particularly stupid forum foul-up in the MIME type quoting of attachment links, they generally will not load as such in the browser. :roll_eyes:

I get it ...
Anyway what about my question? Any Ideas?
Was the 100k resistor on my button too big?