Skip to content

Instantly share code, notes, and snippets.

@takahisa
Created February 27, 2013 01:08
Show Gist options
  • Save takahisa/5043995 to your computer and use it in GitHub Desktop.
Save takahisa/5043995 to your computer and use it in GitHub Desktop.
hohe
#include <Matrix.h>
#include <Sprite.h>
const int censorPin = 1;
Matrix mtx = Matrix(10, 12, 11);
void setup() {
pinMode(censorPin, INPUT);
mtx.clear();
}
void loop() {
mtx.clear();
int row = analogRead(censorPin);
int v = mapf(row, 0, 512, 0, 64);
int x = 0;
int y = 0;
mtx.write(x, y, HIGH);
for(int i = 0; i < v; i++) {
if(i < 7) {
y++;
} else if(i < 14) {
x++;
} else if(i < 21) {
y--;
} else if(i < 27) {
x--;
} else if(i < 33) {
y++;
} else if(i < 38) {
x++;
} else if(i < 43) {
y--;
} else if(i < 47) {
x--;
} else if(i < 51) {
y++;
} else if(i < 54) {
x++;
} else if(i < 57) {
y--;
} else if(i < 59) {
x--;
} else if(i < 61) {
y++;
} else if(i == 61) {
x++;
} else if(i == 62){
y--;
} else {
x--;
}
mtx.write(x, y, HIGH);
}
delay(100);
}
float mapf(float x, float imin, float imax, float omin, float omax) {
return (x - imin) * (omax - omin) / (imax - imin) + omin;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment