That sounds good.
To hep you locate your code bugs, try using the Serial Monitor and place Serial.prints in your code so you can 'see' whats actually happening as the code runs.
However on your diagram there are problems.
You cannot drive high powered leds directly from the chip / P1, it will simply burn out the chip.
You show Vin connected to the LED driver ? What are you using as the Led Driver ?
A led driver typically uses a control signal from the Micro/ Digispark, often a PWM signal, so it can drive the leds at various brightness.
For your input from the motion detector, the DP should accept 3v3 directly, my Arduino does, however you may want to protect both circuits by using a little opto coupler.
There are many similar devices , not just the one shown in the diagram.
You will probably have to lower the leds input resistor to that shown in the diagram, try 330R if you do not have a multimeter.
Great info! I did consider that putting the supply directly through the Vin would not be feasible, so I do plan to use a PWM capable led driver (I already have it) on a 12v battery circuit to feed the leds via an PNP transistor(?). I will update my schematic and post it soon. I like the idea of incorporating the serial.prints in my code to verify what is happening. I will look into that (tutorials).
One question:
I did decide to swap the function of my code, putting the fade sequence before the delay loop. The code reads pin PO and if high, executes the fade, otherwise, it will show me several 1/2 sec blinks then loop back and start over. I'll change the blink code, when I know the sketch is flowing properly. However, no matter what I do, when I try to verify my sketch, } else { is highlighted and it tells me that there is either 'else without previous if'', or 'expected unqualified-id before '{' token'. I cannot get past it. I have fixed this issue in previous versions of my sketch, but am now stuck.What am I missing?
Code:
/*
updown_fade
This example shows how to fade an LED in/out using the analogWrite() function.
The circuit:
* LED (+) attached to pin 1. (3.3v w/ resistor)
* motion sensor 'signal' will be attached to pin 2 (for now I am just attaching and detatching a 3.3v lead to pin2)
* digispark microcontroller on breadboard (prototyping)
Created 7/15/2017
By John A. Austin
*/
int sensorValue = 0; //analog value of sensorPin (P0) when off
int sensorPin = 2; //motion sensor out pin connected to digital pin 2 (P0 on digispark)
int ledPin = 1; // LED connected to digital pin 1
int fadeValue = 0; //initial led brightness (variable)
//int analogValue = analogRead(ledPin);
void setup()
{
// initialize the sensorPin as an input:
pinMode(sensorPin, INPUT);
// initialize the ledPin as an output:
pinMode(ledPin, OUTPUT);
}
void loop() {
if(digitalRead(sensorPin) == HIGH)
for (int fadeValue = 0 ; fadeValue <= 255 ; fadeValue += 1)
{
analogWrite(ledPin, fadeValue);
delay(235);
}
{
analogWrite(ledPin, 0);
delay(2000);
analogWrite(ledPin, 5);
delay(5000);
for (int fadeValue = 255 ; fadeValue >= 0; fadeValue -= 1)
analogWrite(ledPin, fadeValue);
delay(125);
analogWrite(ledPin, 5);
delay(5000);
} else {
analogWrite(ledPin, 255);
delay(500);
analogWrite(ledPin, 0);
delay(500)
loop(5);
}