From: Ivan Stefanov Date: Thu, 10 Dec 2020 14:19:20 +0000 (+0200) Subject: Demo test example X-Git-Url: https://kolegite.com/gitweb/?a=commitdiff_plain;h=4a87a35a6b68566a48f4639d2c9b26ec03b0ffa6;p=vmks.git Demo test example Решение на примерното контролно решавано по време на часовете --- diff --git a/Examples/Demo_test/Demo_test - Tinkercad - Schematic.png b/Examples/Demo_test/Demo_test - Tinkercad - Schematic.png new file mode 100644 index 0000000..c6be61c Binary files /dev/null and b/Examples/Demo_test/Demo_test - Tinkercad - Schematic.png differ diff --git a/Examples/Demo_test/Demo_test.ino b/Examples/Demo_test/Demo_test.ino new file mode 100644 index 0000000..f32ab5b --- /dev/null +++ b/Examples/Demo_test/Demo_test.ino @@ -0,0 +1,79 @@ +#include +#define NUM_PIXELS 10 +#define PIN 12 +Adafruit_NeoPixel strip(NUM_PIXELS, PIN, NEO_GRB); + +#define BTN 2 + +uint8_t colorToggle = 0; + +void changeColor(); + +#define A1 5 +#define A2 6 +#define EN1 13 + +#define POT A3 + +uint16_t count = 0; + +void setup() +{ + strip.begin(); + //changeColor(); + pinMode(2, INPUT_PULLUP); + attachInterrupt(digitalPinToInterrupt(BTN), changeColor, FALLING); + + pinMode(POT, INPUT); + pinMode(A1, OUTPUT); + pinMode(A2, OUTPUT); + pinMode(EN1, OUTPUT); + digitalWrite(EN1, HIGH); + + TCCR1A = 0; + TCCR1B = 0; + TCNT1 = 0; + OCR1A = 0; + OCR1B = 0; + ICR1 = 0; + TIMSK1 = 0; + TIFR1 = 0; + + TCCR1A |= (1 << WGM11) | (1 << COM1B1); + TCCR1B |= (1 << WGM12) | (1 << WGM13); + OCR1B = 781; + ICR1 = 1249; + + TCCR1B |= (1 << CS10) | (1 << CS11); + + //Serial.begin(115200); +} + +void loop() +{ + uint16_t pot_value = analogRead(POT); + pot_value = map(pot_value, 0, 1023, 0, 255); + analogWrite(A1, pot_value); + digitalWrite(A2, LOW); +} + +void changeColor() +{ + if (colorToggle == 1) + { + strip.setPixelColor(2, strip.Color(0, 255, 0)); + colorToggle = 0; + } + else + { + strip.setPixelColor(2, strip.Color(255, 255, 255)); + colorToggle = 1; + } + strip.show(); +} + +ISR(TIMER1_OVF_vect) +{ + count++; + //Serial.println(count); +}