#include <FastLED.h>
//#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
#define NUM_LEDS 60
#define LED_PIN 5
#define ANALOG_PIN 4
#define SW_PIN 2
CRGB leds[NUM_LEDS];
bool check = false;
void IRAM_ATTR interrupt_Function() {
// Function code
if (check == false) {
leds[2] = CRGB::Aquamarine;
check = true;
} else {
leds[2] = CRGB::DarkViolet;
check = false;
}
Serial.println(check);
}
void setup() {
FastLED.addLeds<WS2812B, LED_PIN, GRB>(leds, NUM_LEDS);
//FastLED.setBrightness(100);
Serial.begin(115200);
pinMode(SW_PIN, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(SW_PIN), interrupt_Function, FALLING);
}
vector<vector<string>> matrix{{"a", "b", "c"}, {"d", "e", "f"}, {"g", "h", "i"}};
vector<vector<string>> matrix2{{"a", "b", "c"}, {"d", "e", "f"}, {"g", "h", "i"}};
vector<vector<CRGB>> colors{
{ 0x000000 ,0x000000 ,0x000000 ,0x000000 ,0x000000 ,0x000000 ,0x000000 ,0x000000 ,0x000000 ,0x000000 ,0x000000 ,0x000000 ,0x000000 ,0x000000 ,0x000000 ,0x000000 },
{ 0x000000 ,0x000000 ,0x000000 ,0x000000 ,0x000000 ,0x000000 ,0x000000 ,0x000000 ,0x000000 ,0x000000 ,0x000000 ,0x000000 ,0x000000 ,0x000000 ,0x000000 ,0x000000 },
{ 0x000000 ,0x000000 ,0x000000 ,0x000000 ,0x000000 ,0x000000 ,0x000000 ,0x000000 ,0x000000 ,0x000000 ,0x000000 ,0x000000 ,0x000000 ,0x000000 ,0x000000 ,0x000000 },
{ 0x000000 ,0x000000 ,0xff0000 ,0x000000 ,0x000000 ,0x000000 ,0x000000 ,0x000000 ,0xff0000 ,0x000000 ,0xffffff ,0x000000 ,0x000000 ,0x000000 ,0x000000 ,0x000000 },
{ 0x000000 ,0x000000 ,0xff0000 ,0x000000 ,0x000000 ,0x000000 ,0x000000 ,0xff0000 ,0x000000 ,0x000000 ,0xffffff ,0x000000 ,0x000000 ,0x000000 ,0x000000 ,0x000000 },
{ 0x000000 ,0x000000 ,0xff0000 ,0x000000 ,0x000000 ,0x000000 ,0xff0000 ,0x000000 ,0x000000 ,0x000000 ,0xffffff ,0x000000 ,0x000000 ,0x000000 ,0x000000 ,0x000000 },
{ 0x000000 ,0x000000 ,0xff0000 ,0x000000 ,0x000000 ,0xff0000 ,0x000000 ,0x000000 ,0x000000 ,0x000000 ,0xffffff ,0x000000 ,0x000000 ,0x000000 ,0x000000 ,0x000000 },
{ 0x000000 ,0x000000 ,0xff0000 ,0x000000 ,0xff0000 ,0x000000 ,0x000000 ,0x000000 ,0x000000 ,0x000000 ,0xffffff ,0x000000 ,0x000000 ,0x000000 ,0x000000 ,0x000000 },
{ 0x000000 ,0x000000 ,0xff0000 ,0xff0000 ,0xff0000 ,0x000000 ,0x000000 ,0x000000 ,0x000000 ,0x000000 ,0xffffff ,0x000000 ,0x000000 ,0x000000 ,0x000000 ,0x000000 },
{ 0x000000 ,0x000000 ,0xff0000 ,0x000000 ,0xff0000 ,0x000000 ,0x000000 ,0x000000 ,0x000000 ,0x000000 ,0xffffff ,0x000000 ,0x000000 ,0x000000 ,0x000000 ,0x000000 },
{ 0x000000 ,0x000000 ,0xff0000 ,0x000000 ,0x000000 ,0xff0000 ,0x000000 ,0x000000 ,0x000000 ,0x000000 ,0xffffff ,0x000000 ,0x000000 ,0x000000 ,0x000000 ,0x000000 },
{ 0x000000 ,0x000000 ,0xff0000 ,0x000000 ,0x000000 ,0x000000 ,0xff0000 ,0x000000 ,0x000000 ,0x000000 ,0xffffff ,0x000000 ,0x000000 ,0x000000 ,0x000000 ,0x000000 },
{ 0x000000 ,0x000000 ,0xff0000 ,0x000000 ,0x000000 ,0x000000 ,0x000000 ,0xff0000 ,0x000000 ,0x000000 ,0xffffff ,0x000000 ,0x000000 ,0x000000 ,0x000000 ,0x000000 },
{ 0x000000 ,0x000000 ,0xff0000 ,0x000000 ,0x000000 ,0x000000 ,0x000000 ,0x000000 ,0xff0000 ,0x000000 ,0xffffff ,0x000000 ,0x000000 ,0x000000 ,0x000000 ,0x000000 },
{ 0x000000 ,0x000000 ,0x000000 ,0x000000 ,0x000000 ,0x000000 ,0x000000 ,0x000000 ,0x000000 ,0x000000 ,0x000000 ,0x000000 ,0x000000 ,0x000000 ,0x000000 ,0x000000 },
{ 0x000000 ,0x000000 ,0x000000 ,0x000000 ,0x000000 ,0x000000 ,0x000000 ,0x000000 ,0x000000 ,0x000000 ,0x000000 ,0x000000 ,0x000000 ,0x000000 ,0x000000 ,0x000000 },
};
void loop() {
leds[0] = CRGB::Aqua;
FastLED.show();
delay(1000);
leds[0] = CRGB::Fuchsia;
FastLED.show();
delay(1000);
for (auto &row : colors) {
//Rotate left: rotate content of row
std::rotate(row.begin(), row.begin() + 1, row.end());
}
for (int i = 0; i < colors.size(); i++) {
for (int j = 0; j < colors[i].size(); j++) {
cout << colors[i][j] << " ";
}
cout << '\n';
}
cout << "1:\n" << endl;
for (auto &row : matrix) {
//Rotate left: rotate content of row
std::rotate(row.begin(), row.begin() + 1, row.end());
}
for (int i = 0; i < matrix.size(); i++) {
for (int j = 0; j < matrix[i].size(); j++) {
cout << matrix[i][j] << " ";
}
cout << '\n';
}
cout << "2:\n" << endl;
//Rotate row up, Rotate content of collumn
std::rotate(matrix2.begin(), matrix2.begin() + 1, matrix2.end());
for (int i = 0; i < matrix2.size(); i++) {
for (int j = 0; j < matrix2[i].size(); j++) {
cout << matrix2[i][j] << " ";
}
cout << '\n';
}
std::vector<int> vec{ 10, 20, 30, 30, 20, 10, 10, 20 };
std::vector<int> ve{ 10, 20, 30, 30, 20, 10, 10, 20 };
// Print original vector
std::cout << "Original vector :";
for (int i = 0; i < vec.size(); i++)
std::cout << " " << vec[i];
std::cout << "\n";
// Iterator that store the position of last element
std::vector<int>::iterator pend;
// std :: remove function call
pend = std::remove(vec.begin(), vec.end(), 20);
// Print the vector after std :: remove
std::cout << "Range contains:";
for (std::vector<int>::iterator p = vec.begin(); p != pend; ++p)
std::cout << ' ' << *p; std::cout << '\n';
// Print original vector
std::cout << "Original Vector :";
for (int i = 0; i < ve.size(); i++)
std::cout << " " << ve[i];
std::cout << "\n";
// std :: vector :: erase function call
// erase the first 3 elements of vector
ve.erase(ve.begin(), ve.begin() + 3);
// Print the vector
std::cout << "Vector contains :";
for (int i = 0; i < ve.size(); i++)
std::cout << " " << ve[i];
std::cout << "\n";
}