Last active
August 29, 2015 14:23
-
-
Save Zhigalov/85efd36d37350ba8917a to your computer and use it in GitHub Desktop.
Arduino
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Normal'noe Demo | |
by pocony | |
*/ | |
#include <SPI.h> | |
#include <Ethernet.h> | |
// Enter a MAC address and IP address for your controller below. | |
// The IP address will be dependent on your local network: | |
byte mac[] = { 0x00, 0xAA, 0xBB, 0xCC, 0xDA, 0x02 }; | |
IPAddress ip(191,11,1,1); | |
// Initialize the Ethernet server library | |
// with the IP address and port you want to use | |
// (port 80 is default for HTTP): | |
EthernetServer server(80); | |
int CLK = 15; | |
int DAT = 14; | |
int R = 11; | |
int G = 12; | |
int B = 13; | |
int trackNumber = 0; | |
void setup() | |
{ | |
digitalWrite(16, HIGH); | |
delay(200); | |
pinMode(R, OUTPUT); | |
pinMode(G, OUTPUT); | |
pinMode(B, OUTPUT); | |
pinMode(CLK, OUTPUT); | |
pinMode(DAT, OUTPUT); | |
pinMode(16, OUTPUT); | |
Ethernet.begin(mac, ip); | |
server.begin(); | |
delay(200); | |
} | |
void loop() | |
{ | |
EthernetClient client = server.available(); | |
if (client) { | |
boolean urlParsingMode = true; | |
String buffer = ""; | |
String params[16]; | |
int currentParamIndex = 0; | |
while (client.connected()) { | |
if (!client.available()) { | |
break; | |
} | |
if (urlParsingMode) { | |
char c = client.read(); | |
if (c == '\n' || c == '\r') { | |
params[currentParamIndex] = String(buffer); | |
urlParsingMode = false; | |
continue; | |
} | |
// GET /functionName/param1/param2/... | |
if (c == '/' || c == ' ') { | |
params[currentParamIndex] = String(buffer); | |
buffer = ""; | |
currentParamIndex++; | |
} | |
else { | |
buffer += c; | |
} | |
} | |
else { | |
client.println("HTTP/1.1 204 No Content"); | |
client.println(); | |
break; | |
} | |
} | |
delay(2000); | |
client.stop(); | |
String method = params[2]; | |
if (method == "status") { | |
setStatus(params[3], params[4]); | |
} | |
} | |
} | |
void(* resetFunc) (void) = 0; | |
void setStatus(String status, String trackId) { | |
cleanStatus(); | |
if (status == "ok") { | |
digitalWrite(G, HIGH); | |
} | |
if (status == "fail") { | |
digitalWrite(R, HIGH); | |
playTrack(trackId.toInt()); | |
delay(5000); | |
// playTrack(0xffff); | |
// digitalWrite(DAT, HIGH); | |
digitalWrite(16, LOW); | |
} | |
} | |
//idk how this fucking magic works, i'm sorry :C | |
//void multipleTracks(int firstId, int secondId) { | |
// playTrack(firstId); | |
// stopTrack(1000); | |
// | |
// digitalWrite(DAT, LOW); | |
// delay(666); | |
// digitalWrite(DAT, HIGH); | |
// | |
// playTrack(secondId); | |
// stopTrack(11000); | |
//} | |
void playTrack(int data) | |
{ | |
digitalWrite(CLK, LOW); | |
delay(2); | |
for (int i=15; i>=0; i--) | |
{ | |
delayMicroseconds(50); | |
if((data>>i)&0x0001 >0) | |
{ | |
digitalWrite(DAT, HIGH); | |
} | |
else | |
{ | |
digitalWrite(DAT, LOW); | |
} | |
delayMicroseconds(50); | |
digitalWrite(CLK, HIGH); | |
delayMicroseconds(50); | |
if(i>0) | |
digitalWrite(DAT, LOW); | |
else | |
digitalWrite(DAT, HIGH); | |
delayMicroseconds(50); | |
if(i>0) | |
digitalWrite(CLK, LOW); | |
else | |
digitalWrite(CLK, HIGH); | |
} | |
delay(20); | |
} | |
void cleanStatus() { | |
digitalWrite(R, LOW); | |
digitalWrite(G, LOW); | |
digitalWrite(B, LOW); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Web Server Demo | |
thrown together by Randy Sarafan | |
A simple web server that changes the page that is served, triggered by a button press. | |
Circuit: | |
* Ethernet shield attached to pins 10, 11, 12, 13 | |
* Connect a button between Pin D2 and 5V | |
* Connect a 10K resistor between Pin D2 and ground | |
Based almost entirely upon Web Server by Tom Igoe and David Mellis | |
Edit history: | |
created 18 Dec 2009 | |
by David A. Mellis | |
modified 4 Sep 2010 | |
by Tom Igoe | |
*/ | |
#include <SPI.h> | |
#include <Ethernet.h> | |
#include "LedControlMS.h" | |
#define NBR_MTX 1 | |
LedControl lc=LedControl(7,6,5, NBR_MTX); | |
// Enter a MAC address and IP address for your controller below. | |
// The IP address will be dependent on your local network: | |
byte mac[] = { 0x00, 0xAA, 0xBB, 0xCC, 0xDA, 0x02 }; | |
IPAddress ip(191,11,1,1); | |
int digitCounter=0; | |
// Initialize the Ethernet server library | |
// with the IP address and port you want to use | |
// (port 80 is default for HTTP): | |
EthernetServer server(80); | |
void setup() | |
{ | |
Ethernet.begin(mac, ip); | |
server.begin(); | |
Serial.begin (9600); | |
Serial.println("Setup"); | |
digitCounter=0; | |
for (int i=0; i< NBR_MTX; i++){ | |
lc.shutdown(i,false); | |
/* Set the brightness to a medium values */ | |
lc.setIntensity(i,8); | |
/* and clear the display */ | |
lc.clearDisplay(i); | |
} | |
} | |
void loop() | |
{ | |
EthernetClient client = server.available(); | |
if (client) { | |
boolean currentLineIsBlank = true; | |
boolean isUrl = true; | |
int position = 0; | |
String request = ""; | |
while (client.connected()) { | |
if (!client.available()) { | |
break; | |
} | |
char c = client.read(); | |
position++; | |
if (position > 5 && isUrl) { | |
if (c == ' ') { | |
isUrl = false; | |
} else { | |
request += c; | |
} | |
} | |
if (c == '\n' && currentLineIsBlank) { | |
client.println("HTTP/1.1 200 OK"); | |
client.println("Content-Type: text/html"); | |
client.println(); | |
client.println("4"); | |
client.println("<pre>" + request + "</pre>"); | |
scrollString(" " + request); | |
delay(1000); | |
lc.clearAll(); | |
break; | |
} else if (c == '\n') { | |
currentLineIsBlank = true; | |
} | |
else if (c != '\r') { | |
currentLineIsBlank = false; | |
} | |
} | |
delay(1); | |
client.stop(); | |
} | |
} | |
void scrollString(String displayString) { | |
int width = 6; | |
int len = displayString.length(); | |
for (int scroll = 0; scroll < width * len; scroll++) { | |
for (char charIndex = 0; charIndex < len; charIndex++ ){ | |
int pos =lc.getCharArrayPosition(displayString[charIndex]); | |
for (int i=0; i < width; i++) { | |
if (charIndex * width + i-scroll<8) lc.setRow(0,charIndex * width + i-scroll, alphabetBitmap[pos][i]); | |
} | |
} | |
delay(300); | |
lc.clearDisplay(0); | |
} | |
} | |
void scrollLeft(char ch){ | |
int pos =lc.getCharArrayPosition(ch); | |
for (int scroll =0; scroll<6; scroll++) { | |
for (int i=scroll; i<6;i++) { | |
lc.setRow(0,i-scroll, alphabetBitmap[pos][i]); | |
} | |
delay(300); | |
lc.clearDisplay(0); | |
} | |
} | |
void scrollRight(char ch){ | |
int pos =lc.getCharArrayPosition(ch); | |
for (int scroll =0; scroll<8; scroll++) { | |
for (int i=0; i<6;i++) { | |
if (scroll+i<8) lc.setRow(0, scroll+i, alphabetBitmap[pos][i]); | |
} | |
delay(300); | |
lc.clearDisplay(0); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Web Server Demo | |
thrown together by Randy Sarafan | |
A simple web server that changes the page that is served, triggered by a button press. | |
Circuit: | |
* Ethernet shield attached to pins 10, 11, 12, 13 | |
* Connect a button between Pin D2 and 5V | |
* Connect a 10K resistor between Pin D2 and ground | |
Based almost entirely upon Web Server by Tom Igoe and David Mellis | |
Edit history: | |
created 18 Dec 2009 | |
by David A. Mellis | |
modified 4 Sep 2010 | |
by Tom Igoe | |
*/ | |
#include <SPI.h> | |
#include <Ethernet.h> | |
// Enter a MAC address and IP address for your controller below. | |
// The IP address will be dependent on your local network: | |
byte mac[] = { 0x00, 0xAA, 0xBB, 0xCC, 0xDA, 0x02 }; | |
IPAddress ip(191,11,1,1); | |
// Initialize the Ethernet server library | |
// with the IP address and port you want to use | |
// (port 80 is default for HTTP): | |
EthernetServer server(80); | |
int red = 11; | |
int green = 12; | |
int blue = 13; | |
void setup() | |
{ | |
Ethernet.begin(mac, ip); | |
server.begin(); | |
Serial.begin (9600); | |
Serial.println("Setup"); | |
pinMode(red, OUTPUT); | |
pinMode(green, OUTPUT); | |
pinMode(blue, OUTPUT); | |
} | |
void loop() | |
{ | |
EthernetClient client = server.available(); | |
if (client) { | |
boolean urlParsingMode = true; | |
String buffer = ""; | |
String params[16]; | |
int currentParamIndex = 0; | |
while (client.connected()) { | |
if (!client.available()) { | |
break; | |
} | |
if (urlParsingMode) { | |
char c = client.read(); | |
if (c == '\n' || c == '\r') { | |
params[currentParamIndex] = String(buffer); | |
urlParsingMode = false; | |
continue; | |
} | |
// GET /functionName/param1/param2/... | |
if (c == '/' || c == ' ') { | |
params[currentParamIndex] = String(buffer); | |
buffer = ""; | |
currentParamIndex++; | |
} | |
else { | |
buffer += c; | |
} | |
} | |
else { | |
digitalWrite(green, HIGH); | |
client.println("HTTP/1.1 200 OK"); | |
client.println("Content-Type: text/html"); | |
client.println(); | |
for (int i = 0; i < currentParamIndex; i++) { | |
client.println(params[i]); | |
} | |
break; | |
} | |
} | |
delay(1000); | |
client.stop(); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//We always have to include the library | |
#include "LedControlMS.h" | |
/* | |
Now we need a LedControl to work with. | |
***** These pin numbers will probably not work with your hardware ***** | |
pin 12 is connected to the DataIn | |
pin 11 is connected to the CLK | |
pin 10 is connected to LOAD | |
We have only a single MAX72XX. | |
*/ | |
#define NBR_MTX 1 | |
LedControl lc=LedControl(12,11,10, NBR_MTX); | |
String digits= "1234567890"; | |
int digitCounter=0; | |
/* we always wait a bit between updates of the display */ | |
unsigned long delaytime=300; | |
void setup() { | |
/* | |
The MAX72XX is in power-saving mode on startup, | |
we have to do a wakeup call | |
*/ | |
Serial.begin (9600); | |
Serial.println("Setup"); | |
digitCounter=0; | |
for (int i=0; i< NBR_MTX; i++){ | |
lc.shutdown(i,false); | |
/* Set the brightness to a medium values */ | |
lc.setIntensity(i,8); | |
/* and clear the display */ | |
lc.clearDisplay(i); | |
} | |
// Serial.println("LED0: 0 0"); | |
// lc.setLed(0,0,0,true); | |
// delay(1000); | |
// Serial.println("LED0: 0 7"); | |
// lc.setLed(0,0,7,true); | |
// delay(1000); | |
// Serial.println("LED0: 7 0"); | |
// lc.setLed(0,7,0,true); | |
// delay(1000); | |
// Serial.println("LED0: 7 7"); | |
// lc.setLed(0,7,7,true); | |
// delay(1000); | |
// Serial.println("LED0: 0 0 off"); | |
// lc.setLed(0,0,0,false); | |
// delay(1000); | |
// Serial.println("LED0: 0 7 off"); | |
// lc.setLed(0,0,7,false); | |
// delay(1000); | |
// Serial.println("LED0: 7 0 off"); | |
// lc.setLed(0,7,0,false); | |
// delay(1000); | |
// Serial.println("LED0: 7 7 off"); | |
// lc.setLed(0,7,7,false); | |
// delay(1000); | |
// //clearAll(); | |
// | |
// lc.setRow(0,1,0x0C); | |
// delay(1000); | |
// lc.clearDisplay(0); | |
// lc.setRow(0,1,0xC0); | |
// delay(1000); | |
// lc.clearDisplay(0); | |
// | |
// lc.setColumn(0,1,0x0C); | |
// delay(1000); | |
// lc.clearDisplay(0); | |
// lc.setColumn(0,1,0xC0); | |
// delay(1000); | |
// lc.clearDisplay(0); | |
// lc.writeString(0,"Hello, world!"); | |
// delay(1000); | |
// lc.clearAll(); | |
// scrollLeft('O'); | |
// scrollLeft('1'); | |
// delay(1000); | |
// lc.clearAll(); | |
// scrollRight('O'); | |
// delay(1000); | |
// lc.clearAll(); | |
} | |
void loop() { | |
// char ch= digits[digitCounter]; | |
// digitCounter++; | |
// if (digitCounter>9) digitCounter=0; | |
// lc.displayChar(0, lc.getCharArrayPosition(ch)); | |
// delay(1000); | |
// lc.clearAll(); | |
// delay(200); | |
// lc.writeString(0,"Hello, world!"); | |
scrollString("Hello, world!"); | |
delay(1000); | |
lc.clearAll(); | |
} | |
void scrollString(String displayString) { | |
int width = 6; | |
int len = displayString.length(); | |
for (int scroll = 0; scroll < width * len; scroll++) { | |
for (char charIndex = 0; charIndex < len; charIndex++ ){ | |
int pos =lc.getCharArrayPosition(displayString[charIndex]); | |
for (int i=0; i < width; i++) { | |
if (charIndex * width + i-scroll<8) lc.setRow(0,charIndex * width + i-scroll, alphabetBitmap[pos][i]); | |
} | |
} | |
delay(300); | |
lc.clearDisplay(0); | |
} | |
} | |
void scrollLeft(char ch){ | |
int pos =lc.getCharArrayPosition(ch); | |
for (int scroll =0; scroll<6; scroll++) { | |
for (int i=scroll; i<6;i++) { | |
lc.setRow(0,i-scroll, alphabetBitmap[pos][i]); | |
} | |
delay(300); | |
lc.clearDisplay(0); | |
} | |
} | |
void scrollRight(char ch){ | |
int pos =lc.getCharArrayPosition(ch); | |
for (int scroll =0; scroll<8; scroll++) { | |
for (int i=0; i<6;i++) { | |
if (scroll+i<8) lc.setRow(0, scroll+i, alphabetBitmap[pos][i]); | |
} | |
delay(300); | |
lc.clearDisplay(0); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment