
#include <Adafruit_NeoPixel.h>
#include "SCoop.h"
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <DHT.h>
#include <SPI.h>
#include <Adafruit_GFX.h>
#include <Max72xxPanel.h>

Adafruit_NeoPixel  rgb_display_6= Adafruit_NeoPixel(8,6,NEO_RGB + NEO_KHZ800);
LiquidCrystal_I2C mylcd(0x27,16,2);
DHT dht2(2, 11);
Max72xxPanel myMatrix = Max72xxPanel(9,1,1);
uint8_t  LEDArray[8];

uint32_t Wheel(byte WheelPos) {
if(WheelPos < 85)
{
return rgb_display_6.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
}
else if(WheelPos < 170)
{
WheelPos -= 85;
return rgb_display_6.Color(255 - WheelPos * 3, 0, WheelPos * 3);
}
 else
 {
WheelPos -= 170;
return rgb_display_6.Color(0, WheelPos * 3, 255 - WheelPos * 3);
}
}

void rainbow(uint8_t wait) {
 uint16_t i, j;
for(j=0; j<256; j++) {
for(i=0; i<rgb_display_6.numPixels(); i++)
 {
rgb_display_6.setPixelColor(i, Wheel((i+j) & 255));
}
rgb_display_6.show();
delay(wait);
}
}

defineTask(scoopTask1)
void scoopTask1::setup()
{
}
void scoopTask1::loop()
{
  rainbow(20);
}

defineTask(scoopTask3)
void scoopTask3::setup()
{
}
void scoopTask3::loop()
{
  mylcd.setCursor(0, 0);
  mylcd.print(String("T:") + String(String(dht2.readTemperature()) + String(String("  ") + String(String("H:") + String(dht2.readHumidity())))));
  mylcd.setCursor(0, 1);
  mylcd.print(String("pot ") + String(analogRead(A0)));
}

defineTask(scoopTask2)
void scoopTask2::setup()
{
}
void scoopTask2::loop()
{
  analogWrite(5,255);
  analogWrite(8,0);
  analogWrite(7,0);
  delay(1000);
  analogWrite(5,0);
  analogWrite(8,255);
  analogWrite(7,0);
  delay(1000);
  analogWrite(5,0);
  analogWrite(8,0);
  analogWrite(7,255);
  delay(1000);
  analogWrite(5,255);
  analogWrite(8,0);
  analogWrite(7,255);
  delay(1000);
}

const uint8_t matrix_img_183c7effffffe742[8] PROGMEM={0x18,0x3c,0x7e,0xff,0xff,0xff,0xe7,0x42};

defineTask(scoopTask4)
void scoopTask4::setup()
{
}
void scoopTask4::loop()
{
  memcpy_P (&LEDArray, &matrix_img_183c7effffffe742, 8);
  for(int index_i=0; index_i<8; index_i++)
  {
    for(int index_j=1*8; index_j<1*8+8; index_j++)
    {
      if((LEDArray[index_i]&0x01)>0)
       myMatrix.drawPixel(index_j, 7-index_i,1);
  else
  myMatrix.drawPixel(index_j, 7-index_i,0);
       LEDArray[index_i] = LEDArray[index_i]>>1;
    }
  }
  myMatrix.write();
  myMatrix.setIntensity((map(analogRead(A1), 1, 1023, 1, 5)));
}

void setup(){
  rgb_display_6.begin();

  mySCoop.start();
  mylcd.init();
  mylcd.backlight();
   dht2.begin();
}

void loop(){
  yield();

}
