Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define NUM_LEDS 4
- #include<SoftwareSerial.h>
- SoftwareSerial s(3, 1);
- #include "FastLED.h"
- #define PIN 13
- CRGB leds[NUM_LEDS];
- int red = 255;
- int green = 255;
- int blue = 255;
- int del = 1000;
- int temp = 0;
- int buf = 0;
- int count = 1000;
- //Вспомогательные функции
- int asciiToInt (int ascii) {
- //АСКИ код нуля - 48
- return ascii - 48;
- }
- int serialToComand () {
- int tempSerial = Serial.read();
- int controlcommand = 0;
- while (tempSerial != -1) {
- controlcommand = controlcommand * 10 + asciiToInt(tempSerial);
- tempSerial = Serial.read();
- Serial.println("");
- Serial.print("tempSerial()=");
- Serial.print(tempSerial);
- Serial.println("");
- }
- return controlcommand;
- }
- CRGB ledRGB (CRGB leds, int red, int green, int blue)
- {
- leds.r = red;
- leds.g = green;
- leds.b = blue;
- return leds;
- }
- void setup() {
- FastLED.addLeds<WS2811, PIN, GRB>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
- FastLED.setBrightness(50);
- pinMode(13, OUTPUT);
- Serial.begin(9600);
- }
- //Режим радуги
- //Режим какого-то определенного цвета
- void flaslight_mode_0 () {
- long inputColors=serialToComand;
- blue=inputColors%1000;
- inputColors=inputColors/1000;
- green=inputColors%1000;
- inputColors=inputColors/1000;
- red=inputColors;
- Serial.println(inputColors);
- for (int i = 0; i < NUM_LEDS; i++ ) {
- leds[i] = ledRGB(leds[i], red, green, blue);
- }
- FastLED.show();
- delay(100);
- }
- void flaslight_mode_1 () {
- byte counter;
- for (int i = 0; i < NUM_LEDS; i++ ) {
- leds[i] = ledRGB(leds[i], red, green, blue);
- }
- FastLED.show();
- delay (del);
- for (int i = 0; i < NUM_LEDS; i++ ) {
- leds[i] = ledRGB(leds[i], 0, 0, 0);
- }
- FastLED.show();
- delay(del); // скорость движения радуги
- }
- void loop() {
- int tempSerial = Serial.read();
- if (tempSerial != -1) {
- Serial.println("");
- Serial.print("tempSerial()=");
- Serial.print(tempSerial);
- Serial.println("");
- int controlcommand = 0;
- while (tempSerial != -1) {
- controlcommand = controlcommand * 10 + asciiToInt(tempSerial);
- tempSerial = Serial.read();
- Serial.println("");
- Serial.print("tempSerial()=");
- Serial.print(tempSerial);
- Serial.println("");
- }
- tempSerial = controlcommand;
- }
- if (tempSerial != -1) Serial.println(tempSerial);
- if ((buf != tempSerial) && (tempSerial >= 0)) {
- buf = tempSerial;
- Serial.println("");
- Serial.println("Buf=");
- Serial.print(buf);
- Serial.println("tempSerial()=");
- Serial.print(tempSerial);
- Serial.println("");
- }
- switch (buf) {
- case 100:
- Serial.println("Mode 0");
- flaslight_mode_0();
- break;
- case 101:
- Serial.println("Mode 1");
- flaslight_mode_1();
- break;
- }
- }
Add Comment
Please, Sign In to add comment