void blinkLED(byte targetPin, int numBlinks, int blinkRate) {
for (int i=0; i < numBlinks; i++) {
digitalWrite(targetPin, HIGH);
delay(blinkRate);
digitalWrite(targetPin, LOW);
delay(blinkRate);
}
}
void blinkNumber(char* numString) {
int versLength = strlen(numString);
delay(200);
for (int i =0 ; i < versLength; i++) {
int number = numString[i] -48;
if (number == 0){
blinkLED(LED_A,1,20);
delay(160);
}
if (number > 0 && number < 10) blinkLED(LED_A,number,200);
delay(400);
}
}
void buzz(int targetPin, long frequency, long length) {
long delayValue = 1000000/frequency/2;
long numCycles = frequency * length/ 1000;
for (long i=0; i < numCycles; i++){
digitalWrite(targetPin,HIGH);
delayMicroseconds(delayValue);
digitalWrite(targetPin,LOW);
delayMicroseconds(delayValue);
}
}
int memoryTest() {
int byteCounter = 0;
byte *byteArray;
while ( (byteArray = (byte*) malloc (byteCounter * sizeof(byte))) != NULL ) {
byteCounter++;
free(byteArray);
}
free(byteArray);
return byteCounter;
}
long mapBig(unsigned long x, unsigned long in_min, unsigned long in_max,
unsigned long out_min, unsigned long out_max) {
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}
if (WiFi.status() == WL_NO_SHIELD) {
Serial.println("WiFi shield not present");
while(true);
}
if ( stringFromCharString(ssid) != "" ) {
while ( status != WL_CONNECTED) {
timesWeTriedToConnect++;
Serial.print(F("Attempting to connect to SSID (attempt "));
Serial.print( timesWeTriedToConnect );
Serial.print(F(" of 5): "));
Serial.println(ssid);
status = WiFi.begin(ssid, pass); // Connect to WPA/WPA2 network.
delay(2000);
if ( timesWeTriedToConnect >= 5 ) break;
}
}
if ( status != WL_CONNECTED ) {
Serial.print("Unable to connect to ssid '");
Serial.print( ssid );
Serial.println( "'");
Serial.println("** Scanning for open networks **");
byte numSsid = WiFi.scanNetworks();
Serial.print("number of available networks:");
Serial.println(numSsid);
for (int thisNet = 0; thisNet Serial.print(thisNet);
Serial.print(") ");
Serial.print(WiFi.SSID(thisNet));
Serial.print("\tSignal: ");
Serial.print(WiFi.RSSI(thisNet));
Serial.print(" dBm");
Serial.print("\tEncryption: ");
Serial.println(WiFi.encryptionType(thisNet));
if ( WiFi.encryptionType(thisNet) == 7 ) {
Serial.println( "Attempting to connect to open network...");
status = WiFi.begin( WiFi.SSID(thisNet));
delay(10000);
if( status == WL_CONNECTED ) break;
}
}
}
if ( status != WL_CONNECTED ) {
Serial.println( "Unable to connect to network" );
// don't continue:
while(true);
}
void setNumber(unsigned long ctr) {
Serial.print("Setting number in EEPROM to = ");
Serial.println( ctr );
EEPROM.write(4,(ctr & 0xFFFFFFFF) >> 24); // MSB 기록
EEPROM.write(3,(ctr & 0xFFFFFF) >> 16); // 3rdB 기록
EEPROM.write(2,(ctr & 0xFFFF) >> 8); // 2ndB 기록
EEPROM.write(1,ctr & 0xFF); // LSB 기록
}
unsigned long getNumber() {
unsigned long ctr;
//숫자 초기화
if (EEPROM.read(5) != 1) {
// 저장 상태가 false일 때
Serial.println("Initializing number in EEPROM");
EEPROM.write(1,0); // LSB 0을 기록
EEPROM.write(2,0); // 2ndB 0을 기록
EEPROM.write(3,0); // 3rdB 0을 기록
EEPROM.write(4,0); // MSB 0을 기록
EEPROM.write(5,1); // 저장 상태를 true로 설정
}
//바이트를 더해 32비트 숫자를 알아낸다
ctr = (EEPROM.read(4) << 24) + (EEPROM.read(3) << 16) + (EEPROM.read(2) << 8 )
+ (EEPROM.read(1));
Serial.print("Getting number from EEPROM = ");
Serial.println( ctr );
return ctr;
}
이전 글 : 아두이노를 사용한 크라우드펀딩 캠페인들
다음 글 : HTML과 CSS 성능 개선
최신 콘텐츠