// Test for SRAM usage with 72 leds in a ledstrip
// Forum: https://forum.arduino.cc/t/controlling-led-strip-with-an-atmega8/1283403
// This Wokwi project: https://wokwi.com/projects/403904696169640961
// Result: 511 bytes are used.


#include <FastLED.h>

#define LED_PIN 2
#define NUM_LEDS 72

int hue = 0;
int huestep = 2;

CRGB leds[NUM_LEDS];

void setup() 
{
  Serial.begin(115200);

  FastLED.addLeds<WS2812B, LED_PIN, GRB>(leds, NUM_LEDS);
  FastLED.clear();

  Serial.println(F("Arduino Nano: 2kbyte SRAM."));
  Serial.println(F("ATmega8: 1kbyte byte SRAM."));
  Serial.print(F("This sketch uses: "));
  Serial.print(2048-freeRam());
  Serial.print(F(" bytes"));
  Serial.println();
}

void loop() 
{
  for(int i=0; i<NUM_LEDS; i++)
  {
    int thisHue = (hue + i) % 255;
    leds[i].setHue(thisHue);
  }
  hue += huestep;
  if(hue > 255)
    hue -= 255;

  FastLED.show();

  delay(20); // slow down the sketch
}

// freeRam from:
//   https://docs.arduino.cc/learn/programming/memory-guide/
//

int freeRam() {
  extern int __heap_start,*__brkval;
  int v;
  return (int)&v - (__brkval == 0  
    ? (int)&__heap_start : (int) __brkval);  
}