
[Night Security Light](https://randomnerdtutorials.com/build-a-night-security-light-with-arduino/)

## The Problem of Arduino Sketch
> **State Machine** is a **behavior model**, which consists of a **finite number of states**. Based on the current state and a given input the machine performs **state transitions** and produces outputs. ([itemis.com](https://www.itemis.com/en/yakindu/state-machine/documentation/user-guide/overview_what_are_state_machines))

notes:
* https://www.smashingmagazine.com/2018/01/rise-state-machines/
## Programming State Machines
* Object Oriented Programming - State Design Pattern
* Procedural Programming - as functions with `switch` statement
## State Day

```cpp
void state_day(){
// on enter
// main loop
// on leave
}
```


wiring with two cables only
notes:
* https://learn.sparkfun.com/tutorials/serial-communication/all

transfering of 8 bits
## Serial Setup
```cpp
Serial.begin(9600);
```
## State Night


LDR (Light Dependent Resistor)
notes:
* https://www.amazon.com/eBoot-Photoresistor-Sensitive-Resistor-Dependent/dp/B01N7V536K

notes:
* https://www.instructables.com/Car-Auto-Light-System/

notes:
* https://forum.arduino.cc/t/how-to-reverse-the-function-of-an-ldr-sensor/52491/7

Notes:
* https://www.circuitbread.com/ee-faq/analog-versus-digital-signal-processing

Notes:
* https://www.circuitbread.com/ee-faq/analog-versus-digital-signal-processing
## Analog to Digital Converter
(A/D Converter)
## Steps of ADC:
1. sampling
2. quantizing
3. encoding

notes:
* https://commons.wikimedia.org/wiki/File:Digital.signal.discret.svg

notes:
* https://de.wikipedia.org/wiki/Datei:Digital.signal.svg

Notes:
* https://www.arrow.com/en/research-and-events/articles/engineering-resource-basics-of-analog-to-digital-converters

$$567 \times \frac{5}{1024} = 567 \times 4.88^{-3} = 2.77V$$
```cpp
int analogRead(int pin);
```
```cpp
int map(
value,
fromLow, fromHigh,
toLow, toHigh
);
```
```cpp
enum state {
DAY,
NIGHT,
LIGHT
};
```