//FINAL CODE

//pulls neopixel and math libraries
#include "neopixel.h"
#include <math.h>

// IMPORTANT: Set pixel COUNT, PIN and TYPE
#define PIXEL_PIN D0
#define PIXEL_COUNT 16
#define PIXEL_TYPE WS2812

//configures neopixel

int pixel_position = 0;
int blinkNum = 5; //begins number of blinks at 5 for all emotions first tweet
int countS = 0;   //counter for how many sad tweets have been sent in a row
int countM = 0;   //counter for how many mad tweets have been sent in a row
int countG = 0;   //counter for how many sad tweets have been sent in a row
int speaker = D1;

int melodyS[] = {1568,0,1976, 0, 2794,0,2794,0,2794,2637, 2349, 2093};
int melodyM[] = {2637,2637,2637,2093,0,2349,2349,2349,1976};
int melodyG[] = {1568,2093,2349,2637,2637,0, 2637,2349,2637, 2093, 2093,0,2093,2349,2637, 2794, 3520,0, 3520, 3136,2794,2637};

int noteDurationsS[] = {4,8,8,8,8,16,8,16,8,8,8,4 };
int noteDurationsM[] = {8,8,8,2,8,8,8,8,2};
int noteDurationsG[] = {8,8,8,4,4,8,8,8,8,4,4,8,8,8,8,4,4,8,8,8,8,4 };

void setup() {
Serial.begin(9600);
strip.begin();
strip.show(); //Initialize all pixels to 'off'
pinMode(speaker, OUTPUT);
}

countG = 0; //returns other functions to 0
countM = 0; //returns other functions to 0

for (int thisNote = 0; thisNote < 12; thisNote++) {
int noteDuration = 1000/noteDurationsS[thisNote];
tone(speaker, melodyS[thisNote],noteDuration);

int pauseBetweenNotes = noteDuration * 1.30;
delay(pauseBetweenNotes);

noTone(speaker);
}

//runs the program twice as many times as we want the light to blink (one for on, one for off)
for(int j = 0; j < blinkNumS*2; j++){
//lights on for even numbers
if(j % 2 == 0) {
for(int i = 0; i < strip.numPixels(); i++){
strip.setPixelColor(i, 0, 0, 255);
strip.show();
}
}
//lights off for odd numbers
else {
for(int i = 0; i < strip.numPixels(); i++){
strip.setPixelColor(i, 0, 0, 0);
strip.show();
}
}
}
}

countG = 0; //returns other functions to 0
countS = 0; //returns other functions to 0

for (int thisNote = 0; thisNote < 9; thisNote++) {
int noteDuration = 1000/noteDurationsM[thisNote];
tone(speaker, melodyM[thisNote],noteDuration);

int pauseBetweenNotes = noteDuration * 1.30;
delay(pauseBetweenNotes);

noTone(speaker);
}

for(int j = 0; j < blinkNumM*2; j++){
if(j % 2 == 0) {
for(int i = 0; i < strip.numPixels(); i++){
strip.setPixelColor(i, 255, 0, 0);
strip.show();
}
}
else {
for(int i = 0; i < strip.numPixels(); i++){
strip.setPixelColor(i, 0, 0, 0);
strip.show();
}
}
}
}

countG = 0; //returns other functions to 0
countS = 0; //returns other functions to 0

for (int thisNote = 0; thisNote < 22; thisNote++) {
int noteDuration = 1000/noteDurationsG[thisNote];
tone(speaker, melodyG[thisNote],noteDuration);

int pauseBetweenNotes = noteDuration * 1.30;
delay(pauseBetweenNotes);

noTone(speaker);
}

for(int j = 0; j < blinkNum*2; j++){
if(j % 2 == 0) {
for(int i = 0; i < strip.numPixels(); i++){
strip.setPixelColor(i, 255, 215, 0);
strip.show();
}
}
else {
for(int i = 0; i < strip.numPixels(); i++){
strip.setPixelColor(i, 0, 0, 0);
strip.show();
}