Michael Klein
Published © CC BY-NC

CalliColor

Neopixelring für Calliope mini mit eigenen Blöcken

IntermediateFull instructions provided30 minutes1,084
CalliColor

Things used in this project

Hardware components

Calliope mini
Calliope mini
×1

Software apps and online services

Upverter
Upverter

Hand tools and fabrication machines

jlcpcb

Story

Read more

Custom parts and enclosures

CalliColor Gerberfile

CalliColor Pfeilmemory von Margot Schubert

CalliColor Flohalarm von Margot Schubert

CalliColor Fang den Floh von Margot Schubert

Schematics

CalliColor auf Upverter

Code

CalliColor.ubl

Plain text
Modul um den Callicolor bequem in microblocks anzusteuern
module CalliColor Output
author 'MicroBlocks & Michael Klein'
version 1 4 
tags led strip rgb circle ws2812 
description 'Control CalliColor 12xNeoPixel (WS2812) RGB LED circle.'
variables _np_pixels 

	spec ' ' 'neoPixelAttach' 'attach _ LED NeoPixel strip to pin _ : has white _' 'num auto bool' 12 '0' false
	spec ' ' 'setNeoPixelColors10' 'setze NeoPixels _ _ _ _ _ _ _ _ _ _ _ _' 'color color color color color color color color color color color color'
	spec ' ' 'clearNeoPixels' 'clear NeoPixels'
	spec ' ' 'neoPixelSetAllToColor' 'set all NeoPixels color _' 'color'
	spec ' ' 'neoPixelSetRainbow' 'setze alle NeoPixels auf Regenbogen'
	spec ' ' 'setNeoPixelColor' 'set NeoPixel _ color _' 'num color' 1
	spec ' ' 'rotateNeoPixelsBy' 'rotate NeoPixels by _' 'auto' 1
	spec 'r' 'colorFromRGB' 'color r _ g _ b _ (0-255)' 'num num num' 0 100 100
	spec 'r' 'randomColor' 'random color'
	spec ' ' '_NeoPixel_ensureInitialized' '_NeoPixel_ensureInitialized'
	spec ' ' '_NeoPixel_rotate' '_NeoPixel_rotate_left _' 'bool' true
	spec ' ' '_NeoPixel_update' '_NeoPixel_update'

to '_NeoPixel_ensureInitialized' {
  if (_np_pixels == 0) {if ((boardType) == 'M5Atom-Matrix') {
    neoPixelAttach 25 '' false
  } ((boardType) == 'D1-Mini') {
    comment 'D1 mini kit'
    neoPixelAttach 7 15 false
  } else {
    neoPixelAttach 12 '0' false
  }}
}

to '_NeoPixel_rotate' left {
  '_NeoPixel_ensureInitialized'
  local 'length' (size _np_pixels)
  if left {
    local 'first' (at 1 _np_pixels)
    for i (length - 1) {
      atPut i _np_pixels (at (i + 1) _np_pixels)
    }
    atPut length _np_pixels first
  } else {
    local 'last' (at length _np_pixels)
    for i (length - 1) {
      atPut ((length - i) + 1) _np_pixels (at (length - i) _np_pixels)
    }
    atPut 1 _np_pixels last
  }
}

to '_NeoPixel_update' {
  '[display:neoPixelSend]' _np_pixels
  waitMicros 100
}

to clearNeoPixels {
  '_NeoPixel_ensureInitialized'
  fillList _np_pixels 0
  '_NeoPixel_update'
}

to colorFromRGB r g b {
  r = (maximum 0 (minimum r 255))
  g = (maximum 0 (minimum g 255))
  b = (maximum 0 (minimum b 255))
  return (((r << 16) | (g << 8)) | b)
}

to neoPixelAttach number pinNumber optionalHasWhite {
  hasWhite = false
  if ((pushArgCount) > 2) {
    hasWhite = optionalHasWhite
  }
  if (or (_np_pixels == 0) (number != (size _np_pixels))) {
    _np_pixels = (newList number)
  }
  fillList _np_pixels 0
  '[display:neoPixelSetPin]' pinNumber hasWhite
}

to neoPixelSetAllToColor color {
  '_NeoPixel_ensureInitialized'
  fillList _np_pixels color
  '_NeoPixel_update'
}

to neoPixelSetRainbow {
  '_NeoPixel_ensureInitialized'
  setNeoPixelColor 1 (colorSwatch 255 0 0 255)
  setNeoPixelColor 2 (colorSwatch 255 127 0 255)
  setNeoPixelColor 3 (colorSwatch 255 254 0 255)
  setNeoPixelColor 4 (colorSwatch 127 255 0 255)
  setNeoPixelColor 5 (colorSwatch 0 255 0 255)
  setNeoPixelColor 6 (colorSwatch 0 255 127 255)
  setNeoPixelColor 7 (colorSwatch 0 255 254 255)
  setNeoPixelColor 8 (colorSwatch 0 127 255 255)
  setNeoPixelColor 9 (colorSwatch 0 0 255 255)
  setNeoPixelColor 10 (colorSwatch 127 0 255 255)
  setNeoPixelColor 11 (colorSwatch 250 0 255 255)
  setNeoPixelColor 12 (colorSwatch 255 0 127 255)
  '_NeoPixel_update'
}

to randomColor {
  local 'n1' (random 100 200)
  local 'n2' (random 0 100)
  if (1 == (random 1 3)) {
    return ((n1 << 16) | (n2 << 8))
  } (1 == (random 1 2)) {
    return ((n2 << 16) | n1)
  } else {
    return ((n1 << 8) | n2)
  }
}

to rotateNeoPixelsBy n {
  '_NeoPixel_ensureInitialized'
  repeat (absoluteValue n) {
    '_NeoPixel_rotate' (n < 0)
  }
  '_NeoPixel_update'
}

to setNeoPixelColor i color {
  '_NeoPixel_ensureInitialized'
  if (and (1 <= i) (i <= (size _np_pixels))) {
    atPut i _np_pixels color
    '_NeoPixel_update'
  }
}

to setNeoPixelColors10 c1 c2 c3 c4 c5 c6 c7 c8 c9 c10 c11 c12 {
  '_NeoPixel_ensureInitialized'
  if ((size _np_pixels) >= 1) {
    atPut 1 _np_pixels c1
  }
  if ((size _np_pixels) >= 2) {
    atPut 2 _np_pixels c2
  }
  if ((size _np_pixels) >= 3) {
    atPut 3 _np_pixels c3
  }
  if ((size _np_pixels) >= 4) {
    atPut 4 _np_pixels c4
  }
  if ((size _np_pixels) >= 5) {
    atPut 5 _np_pixels c5
  }
  if ((size _np_pixels) >= 6) {
    atPut 6 _np_pixels c6
  }
  if ((size _np_pixels) >= 7) {
    atPut 7 _np_pixels c7
  }
  if ((size _np_pixels) >= 8) {
    atPut 8 _np_pixels c8
  }
  if ((size _np_pixels) >= 9) {
    atPut 9 _np_pixels c9
  }
  if ((size _np_pixels) >= 10) {
    atPut 10 _np_pixels c10
  }
  if ((size _np_pixels) >= 11) {
    atPut 11 _np_pixels c11
  }
  if ((size _np_pixels) >= 12) {
    atPut 12 _np_pixels c12
  }
  '_NeoPixel_update'
}

Credits

Michael Klein

Michael Klein

45 projects • 56 followers
Na klar Bio! Oder direkt aus dem Garten ;-)

Comments