hexsha
stringlengths 40
40
| size
int64 5
1.05M
| ext
stringclasses 588
values | lang
stringclasses 305
values | max_stars_repo_path
stringlengths 3
363
| max_stars_repo_name
stringlengths 5
118
| max_stars_repo_head_hexsha
stringlengths 40
40
| max_stars_repo_licenses
listlengths 1
10
| max_stars_count
float64 1
191k
⌀ | max_stars_repo_stars_event_min_datetime
stringdate 2015-01-01 00:00:35
2022-03-31 23:43:49
⌀ | max_stars_repo_stars_event_max_datetime
stringdate 2015-01-01 12:37:38
2022-03-31 23:59:52
⌀ | max_issues_repo_path
stringlengths 3
363
| max_issues_repo_name
stringlengths 5
118
| max_issues_repo_head_hexsha
stringlengths 40
40
| max_issues_repo_licenses
listlengths 1
10
| max_issues_count
float64 1
134k
⌀ | max_issues_repo_issues_event_min_datetime
stringlengths 24
24
⌀ | max_issues_repo_issues_event_max_datetime
stringlengths 24
24
⌀ | max_forks_repo_path
stringlengths 3
363
| max_forks_repo_name
stringlengths 5
135
| max_forks_repo_head_hexsha
stringlengths 40
40
| max_forks_repo_licenses
listlengths 1
10
| max_forks_count
float64 1
105k
⌀ | max_forks_repo_forks_event_min_datetime
stringdate 2015-01-01 00:01:02
2022-03-31 23:27:27
⌀ | max_forks_repo_forks_event_max_datetime
stringdate 2015-01-03 08:55:07
2022-03-31 23:59:24
⌀ | content
stringlengths 5
1.05M
| avg_line_length
float64 1.13
1.04M
| max_line_length
int64 1
1.05M
| alphanum_fraction
float64 0
1
|
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
f05686f9261b5851358468b4e5d2b922a6f15a04
| 2,414
|
ino
|
Arduino
|
Debug.ino
|
LeandroSQ/arduino-midi-drum
|
727d3fbe20e2529e37fbb47956378aa311f85bd9
|
[
"MIT"
] | 4
|
2022-02-22T13:12:47.000Z
|
2022-03-11T01:56:43.000Z
|
Debug.ino
|
LeandroSQ/arduino-midi-drum
|
727d3fbe20e2529e37fbb47956378aa311f85bd9
|
[
"MIT"
] | null | null | null |
Debug.ino
|
LeandroSQ/arduino-midi-drum
|
727d3fbe20e2529e37fbb47956378aa311f85bd9
|
[
"MIT"
] | null | null | null |
#ifdef DEBUG
inline void printSensorConfiguration() {
// Print the sensor configuration
Serial.println("Sensor configuration:");
for (byte i = 0; i < SENSOR_COUNT; i++) {
Sensor* sensor = &sensors[i];
Serial.print(getSensorName(sensor));
Serial.print(" (");
Serial.print(sensor->pin);
Serial.print(")");
Serial.print("\t");
Serial.print("threshold: ");
Serial.print(sensor->threshold);
Serial.print("\t");
Serial.print("min velocity: ");
Serial.print(sensor->minVelocity);
Serial.print("\t");
Serial.print("max velocity: ");
Serial.print(sensor->maxVelocity);
Serial.print("\t");
Serial.print("sensibility: ");
Serial.print(sensor->sensibility);
Serial.println();
}
}
char* getSensorName(Sensor* sensor) {
switch(sensor->pin) {
case SENSOR_TOM_BLUE_PIN: return "TOM_BLUE";
case SENSOR_TOM_RED_PIN: return "TOM_RED";
case SENSOR_TOM_GREEN_PIN: return "TOM_GREEN";
case SENSOR_CRASH_ORANGE_PIN: return "CRASH_ORANGE";
case SENSOR_CRASH_YELLOW_PIN: return "CRASH_YELLOW";
case SENSOR_KICK_PIN: return "KICK";
default: return "Unknown";
}
}
inline void printSensorTrigger(Sensor* sensor, int value, byte velocity) {
Serial.print(getSensorName(sensor));
if (sensor->state == HIGH) {
Serial.print(" triggered -> ");
} else {
Serial.print(" released -> ");
}
Serial.print("\t");
Serial.print("value: ");
Serial.print(value);
// Prints the velocity percentage
if (sensor->state == HIGH) {
Serial.print("\t");
Serial.print("strength: ");
int strength = (int) mapf(velocity, 0.0f, 127.0f, 0.0f, 100.0f);
Serial.print(strength);
Serial.print("%");
}
Serial.println();
}
#endif
#if defined(DEBUG) && defined(DEBUG_PIN)
inline void debugSinglePin() {
int count = 1;
int sum = 0;
for (int i = 0; i < count; i++) {
sum += analogRead(DEBUG_PIN);
};
short int avg = sum / count;
Serial.println(avg);
}
#endif
| 30.556962
| 78
| 0.528169
|
f934e89ca4402a49e5334a02945061a44d77ffab
| 2,614
|
ino
|
Arduino
|
GET.ino
|
RubanZ/Smart_Meter
|
0954961dfd05d6e23b5aef28a905759eba846a83
|
[
"MIT"
] | null | null | null |
GET.ino
|
RubanZ/Smart_Meter
|
0954961dfd05d6e23b5aef28a905759eba846a83
|
[
"MIT"
] | null | null | null |
GET.ino
|
RubanZ/Smart_Meter
|
0954961dfd05d6e23b5aef28a905759eba846a83
|
[
"MIT"
] | null | null | null |
void send_data_POST(String obj){
Serial.println(obj);
httpPOST.begin("http://94.154.14.1/api/data");
httpPOST.addHeader("Content-Type", "application/json");
int httpCodePOST = httpPOST.POST(obj);
String payloadPOST = httpPOST.getString();
Serial.print(httpCodePOST);
Serial.print(" - ");
Serial.println(payloadPOST);
httpPOST.end();
}
String preparation_data(){
//{ "token": 8362592375, "fulldata": [ {"alias": "name_alias", "data": [2147, 71246, 612746, 21846]}, {"alias": "name_alias", "data": [2147, 71246, 612746, 21846]} ] }
String result = "{ \"token\": ";
result += "\"2b6be3eb938bf63ae3326f094ffe43c\"";
result += ", \"fulldata\": ";
result += "[{\"alias\": \"temp\", \"data\": ";
result += String((int)ds18sb20(12, 0));
result += "}, ";
result += "{\"alias\": \"wetness\", \"data\": ";
result += FuncDHT(2);
result += "}, ";
result += "{\"alias\": \"power\", \"data\": \"";
result += String(ATT("0x04"));
result += "\"}, ";
result += "{\"alias\": \"powera\", \"data\": \"";
result += String(ATT("0x01"));
result += "\"}, ";
result += "{\"alias\": \"powerb\", \"data\": \"";
result += String(ATT("0x02"));
result += "\"}, ";
result += "{\"alias\": \"powerc\", \"data\": \"";
result += String(ATT("0x03"));
result += "\"}, ";
result += "{\"alias\": \"current\", \"data\": \"";
result += String(ATT("0x13"));
result += "\"}, ";
result += "{\"alias\": \"voltage\", \"data\": \"";
result += String(ATT("0x2B"));
result += "\"} ";
result += "]}";
return result;
}
void GET() {
String MQTT_mess = "";
String mess = "http://194.87.99.81:70/mearsurements.php";
/*mess += "?id_device=";
mess += Hex_to_int_mac();
mess += "&tem";
mess += String((int)ds18sb20(root["DS_pin"], i));
mess += "&wetness=";
mess += FuncDHT((int)root["wetness_pin"]);
mess += "&power=";
mess += String(ATT("0x04"));
mess += "&powera=";
mess += String(ATT("0x01"));
mess += "&powerb=";
mess += String(ATT("0x02"));
mess += "&powerc=";
mess += String(ATT("0x03"));
mess += "¤t=";
mess += String(ATT("0x13"));
mess += "&voltage=";
mess += String(ATT("0x2B"));
HTTPClient http;
http.begin(mess);
Serial.println(mess);
int httpCode = http.GET();
if (httpCode > 0) {
Serial.printf("[HTTP] GET... code: %d\n", httpCode);
if (httpCode == HTTP_CODE_OK) {
String payload = http.getString();
Serial.println(payload);
}
} else {
Serial.printf("[HTTP] GET... failed, error: %s\n", http.errorToString(httpCode).c_str());
}
http.end();*/
}
| 25.134615
| 169
| 0.540551
|
1078297ddaac11a0fc4592a96294619cabfc57b2
| 1,058
|
ino
|
Arduino
|
Arduino/_nano_firmware/nanoFirmware/nanoFirmware.ino
|
Sensorica/Sensor-Network
|
872be3aad2f31666a88d8544cabe0066cae2f9c8
|
[
"CC0-1.0"
] | 4
|
2016-02-21T22:53:24.000Z
|
2020-05-23T19:57:49.000Z
|
Arduino/_nano_firmware/nanoFirmware/nanoFirmware.ino
|
Sensorica/Sensor-Network
|
872be3aad2f31666a88d8544cabe0066cae2f9c8
|
[
"CC0-1.0"
] | 1
|
2016-06-27T17:47:47.000Z
|
2016-06-27T17:47:47.000Z
|
Arduino/_nano_firmware/nanoFirmware/nanoFirmware.ino
|
Sensorica/Sensor-Network
|
872be3aad2f31666a88d8544cabe0066cae2f9c8
|
[
"CC0-1.0"
] | 5
|
2016-02-11T17:46:23.000Z
|
2020-05-23T19:58:06.000Z
|
int sensorZ_pin = A0;
int sensorY_pin = A1;
int sensorX_pin = A2;
int sensorZ = 0;
int sensorY = 0;
int sensorX = 0;
int digitalSelectPin = 2;
int digitalSleepPin = 3;
int fft_window = 1000;
int fft_samples[fft_window];
int fft_output[fft_window];
String data;
void setup() {
// declare the ledPin as an OUTPUT:
pinMode(sensorZ, INPUT);
pinMode(sensorY, INPUT);
pinMode(sensorX, INPUT);
pinMode(digitalSelectPin, OUTPUT);
digitalWrite(digitalSelectPin, HIGH); //Set to HIGH for 6G sensitivity, OR LOW for 1.5G sensitivity
digitalWrite(digitalSleepPin, HIGH);
Serial.begin(9600);
}
void loop() {
// read the value from the sensor:
sensorZ = analogRead(sensorZ_pin);
sensorY = analogRead(sensorY_pin);
sensorX = analogRead(sensorX_pin);
// NOTES about the readings:
// Remember that 1G (gravity) is always in effect towards the earth
// The baseline output should be around 337 points
data = "";
data += sensorZ;
data += ",";
data += sensorY;
data += ",";
data += sensorX;
Serial.println(data);
delay(100);
}
| 20.745098
| 101
| 0.699433
|
c1682f4c317020bbf142c9dd852d6d4ee29c8f5e
| 9,923
|
ino
|
Arduino
|
pedal.ino
|
r3stlslzmn/midipedal
|
9bd34b5f2377b93c069c37a2b90b18a6d00637a6
|
[
"MIT"
] | 1
|
2017-01-11T01:59:30.000Z
|
2017-01-11T01:59:30.000Z
|
pedal.ino
|
r3stlslzmn/midipedal
|
9bd34b5f2377b93c069c37a2b90b18a6d00637a6
|
[
"MIT"
] | null | null | null |
pedal.ino
|
r3stlslzmn/midipedal
|
9bd34b5f2377b93c069c37a2b90b18a6d00637a6
|
[
"MIT"
] | null | null | null |
#include <Keypad.h>
#include <EEPROM.h>
#include <SPI.h>
#define NOTE_OFF (0)
#define NOTE_ON (1)
#define MONO (0)
#define POLY (1)
#define EE_ADDR_OCTAVE (0)
#define EE_ADDR_POLY (1)
#define EE_ADDR_CHANNEL (2)
#define VELOCITY (127)
#define HIGH_OCTAVE (9)
#define DOWN_BUTTON (0x1D)
#define CONFIG_BUTTON (0x1E)
#define UP_BUTTON (0x1F)
#define DEBOUNCE_MS (10)
#define HOLD_MS (2000)
#define FLASH_MS (2000)
#define BLINK_PERIOD_MS (500)
#define TLC5916_OE (A5)
#define TLC5916_LE (A4)
// This utility macro function takes a key (0 = c, 1 = c#, 2 = b, etc)
// and the octave number and returns a valid midi note number
// Not that for efficiency, it does not bounds check.
#define MIDI_NOTE_NUM(key, octave) (key - 0x10 + 12 * octave)
enum states {
NORMAL,
OCT_DOWN_PRESSED,
OCT_UP_PRESSED,
CONFIG_PRESSED,
CONFIG_WAIT_RELEASE,
CONFIG,
CHAN_DOWN_PRESSED,
CHAN_UP_PRESSED,
POLY_PRESSED,
NORMAL_WAIT_RELEASE
};
enum flash_states {
OFF,
FLASH,
BLINK_ON,
BLINK_OFF
};
const char hex_character[] = {
0x3F, 0x06, 0x5B, 0x4F, 0x66, 0x6D, 0x7D, 0x07,
0x7F, 0x67, 0x77, 0x7C, 0x39, 0x5E, 0x79, 0x71
};
const char keys[4][4] = {
{0x10, 0x11, 0x12, 0x13},
{0x14, 0x15, 0x16, 0x17},
{0x18, 0x19, 0x1A, 0x1B},
{0x1C, 0x1D, 0x1E, 0x1F}
};
byte row_pins[4] = {6, 7, 8, 9};
byte col_pins[4] = {2, 3, 4, 5};
Keypad switches = Keypad(makeKeymap(keys), row_pins, col_pins, 4, 4);
byte note_status[128];
byte octave;
byte poly;
byte channel;
byte state;
byte seven_seg_state;
byte flash_state;
unsigned long flash_timeout;
void setup() {
byte i;
// turn off yellow LED
pinMode(SS, INPUT);
digitalWrite(SS, LOW);
// Set MIDI baud rate:
Serial1.begin(31250);
// initialize the note status array and status vars
octave = EEPROM.read(EE_ADDR_OCTAVE);
poly = EEPROM.read(EE_ADDR_POLY);
channel = EEPROM.read(EE_ADDR_CHANNEL);
for (i = 0; i < 128; i++) {
note_status[i] = NOTE_OFF;
}
state = NORMAL;
// handle cases where EEPROM gives erroneous values
// (like when it's never been written to before)
if (octave > HIGH_OCTAVE) {
octave = 0;
EEPROM.write(EE_ADDR_OCTAVE, octave);
}
if (channel > 0x0F) {
channel = 0;
EEPROM.write(EE_ADDR_CHANNEL, channel);
}
if (poly > 1) {
poly = 0;
EEPROM.write(EE_ADDR_POLY, poly);
}
// setup keypad class timings
switches.setDebounceTime(DEBOUNCE_MS);
switches.setHoldTime(HOLD_MS);
// init TLC5916 interface and state
SPI.begin();
pinMode(TLC5916_OE, OUTPUT);
digitalWrite(TLC5916_OE, HIGH);
pinMode(TLC5916_LE, OUTPUT);
digitalWrite(TLC5916_LE, LOW);
write_digit(hex_character[octave]);
write_dec_point(poly);
// init seven seg flash timer and state
flash_seven_seg();
}
void loop() {
byte i;
char kchar;
char kstate;
// check flash timeout
if (flash_timeout != 0) {
if (flash_timeout < millis()) {
switch (flash_state) {
case OFF:
flash_timeout = 0;
flash_state = OFF;
break;
case FLASH:
flash_timeout = 0;
digitalWrite(TLC5916_OE, HIGH);
flash_state = OFF;
break;
case BLINK_ON:
flash_timeout = millis() + BLINK_PERIOD_MS / 2;
digitalWrite(TLC5916_OE, HIGH);
flash_state = BLINK_OFF;
break;
case BLINK_OFF:
flash_timeout = millis() + BLINK_PERIOD_MS / 2;
digitalWrite(TLC5916_OE, LOW);
flash_state = BLINK_ON;
break;
}
}
}
// handle switches and buttons
if (switches.getKeys()) {
for (i = 0; i < LIST_MAX; i++) {
if (switches.key[i].stateChanged) {
kchar = switches.key[i].kchar;
kstate = switches.key[i].kstate;
// pedal note switches
if (kchar < DOWN_BUTTON) {
if (kstate == PRESSED) {
if (poly == MONO) {
all_notes_off();
}
note_on(channel, MIDI_NOTE_NUM(kchar, octave), VELOCITY);
note_status[MIDI_NOTE_NUM(kchar, octave)] = NOTE_ON;
} else if (kstate == RELEASED) {
if (note_status[MIDI_NOTE_NUM(kchar, octave)] == NOTE_ON) {
note_off(channel, MIDI_NOTE_NUM(kchar, octave));
note_status[MIDI_NOTE_NUM(kchar, octave)] = NOTE_OFF;
}
}
// octave up, octave down, config switches
} else {
// state machine for stomp switch controls
switch (state) {
case NORMAL:
if (kstate == PRESSED) {
switch (kchar) {
case DOWN_BUTTON:
octave_down();
write_digit(hex_character[octave]);
flash_seven_seg();
state = OCT_DOWN_PRESSED;
break;
case UP_BUTTON:
octave_up();
write_digit(hex_character[octave]);
flash_seven_seg();
state = OCT_UP_PRESSED;
break;
case CONFIG_BUTTON:
flash_seven_seg();
state = CONFIG_PRESSED;
break;
}
}
break;
case OCT_DOWN_PRESSED:
if (kchar == DOWN_BUTTON && kstate == RELEASED) {
state = NORMAL;
}
break;
case OCT_UP_PRESSED:
if (kchar == UP_BUTTON && kstate == RELEASED) {
state = NORMAL;
}
break;
case CONFIG_PRESSED:
if (kchar == CONFIG_BUTTON) {
if (kstate == HOLD) {
write_digit(hex_character[channel]);
blink_seven_seg();
state = CONFIG_WAIT_RELEASE;
} else if (kstate == RELEASED) {
state = NORMAL;
}
}
break;
case CONFIG_WAIT_RELEASE:
if (kchar == CONFIG_BUTTON && kstate == RELEASED) {
state = CONFIG;
}
break;
case CONFIG:
if (kstate == PRESSED) {
switch (kchar) {
case DOWN_BUTTON:
channel_down();
write_digit(hex_character[channel]);
state = CHAN_DOWN_PRESSED;
break;
case UP_BUTTON:
channel_up();
write_digit(hex_character[channel]);
state = CHAN_UP_PRESSED;
break;
case CONFIG_BUTTON:
state = POLY_PRESSED;
break;
}
}
break;
case CHAN_DOWN_PRESSED:
if (kchar == DOWN_BUTTON && kstate == RELEASED) {
state = CONFIG;
}
break;
case CHAN_UP_PRESSED:
if (kchar == UP_BUTTON && kstate == RELEASED) {
state = CONFIG;
}
break;
case POLY_PRESSED:
if (kchar == CONFIG_BUTTON) {
if (kstate == RELEASED) {
toggle_poly();
write_dec_point(poly);
state = CONFIG;
} else if (kstate == HOLD) {
write_digit(hex_character[octave]);
flash_seven_seg();
state = NORMAL_WAIT_RELEASE;
}
}
break;
case NORMAL_WAIT_RELEASE:
if (kchar == CONFIG_BUTTON && kstate == RELEASED) {
state = NORMAL;
}
break;
}
}
}
}
}
}
// continuous rapid blinking
void blink_seven_seg() {
flash_timeout = millis() + BLINK_PERIOD_MS / 2;
digitalWrite(TLC5916_OE, LOW);
flash_state = BLINK_ON;
}
// one-shot flash of longer duration
void flash_seven_seg() {
flash_timeout = millis() + FLASH_MS;
digitalWrite(TLC5916_OE, LOW);
flash_state = FLASH;
}
// write the seven segment digit preserving the decimal point
void write_digit(byte digit) {
seven_seg_state = (seven_seg_state & 0x80) | (digit & 0x7F);
SPI.transfer(seven_seg_state);
digitalWrite(TLC5916_LE, HIGH);
digitalWrite(TLC5916_LE, LOW);
}
// write the seven segment decimal preserving the digit
void write_dec_point(byte dec_point) {
seven_seg_state = (seven_seg_state & 0x7F) | (dec_point << 7);
SPI.transfer(seven_seg_state);
digitalWrite(TLC5916_LE, HIGH);
digitalWrite(TLC5916_LE, LOW);
}
void octave_down() {
all_notes_off();
if (octave > 0) {
octave--;
EEPROM.write(EE_ADDR_OCTAVE, octave);
}
}
void octave_up() {
all_notes_off();
if (octave < HIGH_OCTAVE) {
octave++;
EEPROM.write(EE_ADDR_OCTAVE, octave);
}
}
void channel_down() {
all_notes_off();
if (channel > 0) {
channel--;
EEPROM.write(EE_ADDR_CHANNEL, channel);
}
}
void channel_up() {
all_notes_off();
if (channel < 0x0F) {
channel++;
EEPROM.write(EE_ADDR_CHANNEL, channel);
}
}
void toggle_poly() {
all_notes_off();
poly = !poly;
EEPROM.write(EE_ADDR_POLY, poly);
}
// turn off all notes flagged as having been turned on
void all_notes_off() {
byte j;
for (j = 0; j < 128; j++) {
if (note_status[j] == NOTE_ON) {
note_off(channel, j);
note_status[j] = NOTE_OFF;
}
}
}
// send MIDI note-on message
void note_on(byte channel, byte pitch, byte velocity) {
Serial1.write(0x90 | (channel & 0x0F));
Serial1.write(pitch & 0x7F);
Serial1.write(velocity & 0x7F);
}
// send MIDI note-off message
void note_off(byte channel, byte pitch) {
Serial1.write(0x80 | (channel & 0x0F));
Serial1.write(pitch & 0x7F);
Serial1.write(127); // velocity
}
| 25.97644
| 71
| 0.553462
|
ed22265859963d1276515a8c7efb329fb43e0e46
| 408
|
ino
|
Arduino
|
ex14/ex14.ino
|
suhasksv/arduinoid
|
1b14d2818746b8da276c6d2791bdfa622cdcbd52
|
[
"MIT"
] | 3
|
2019-06-05T12:42:24.000Z
|
2020-07-06T09:01:53.000Z
|
ex14/ex14.ino
|
suhasksv/arduinoid
|
1b14d2818746b8da276c6d2791bdfa622cdcbd52
|
[
"MIT"
] | null | null | null |
ex14/ex14.ino
|
suhasksv/arduinoid
|
1b14d2818746b8da276c6d2791bdfa622cdcbd52
|
[
"MIT"
] | null | null | null |
const int datapin = 2;
const int clockpin = 3;
const int latchpin = 4;
void setup() {
pinMode(datapin, OUTPUT);
pinMode(clockpin, OUTPUT);
pinMode(latchpin, OUTPUT);
}
void loop() {
digitalWrite(latchpin, LOW);
shiftOut(datapin, clockpin, LSBFIRST, 255);
digitalWrite(latchpin, HIGH);
delay(1000);
shiftOut(datapin, clockpin, LSBFIRST, 0);
digitalWrite(latchpin, HIGH);
delay(1000);
}
| 19.428571
| 45
| 0.696078
|
90a143741ae268b4870c95addf964c748620f1f7
| 550
|
ino
|
Arduino
|
Exercise_2_Ans/Exercise_2_Ans.ino
|
GoshBird/Mei-i-t
|
ac2d7cee047920e3282b34e611084db6c51abc6e
|
[
"MIT"
] | null | null | null |
Exercise_2_Ans/Exercise_2_Ans.ino
|
GoshBird/Mei-i-t
|
ac2d7cee047920e3282b34e611084db6c51abc6e
|
[
"MIT"
] | null | null | null |
Exercise_2_Ans/Exercise_2_Ans.ino
|
GoshBird/Mei-i-t
|
ac2d7cee047920e3282b34e611084db6c51abc6e
|
[
"MIT"
] | null | null | null |
//#define 名前 ピン番号 を事前に書くことでピン番号ではなくて名前で管理できるようになります。
#define LED 2
#define Button 8
//int 名前 で変数(整数)を定義できます。ちなみに、他にもfloatやdoubleなどがあります。それぞれ入れれる数字が異なっているので時と場合で使い分けます。
int val = LOW;
void setup() {
Serial.begin(9600);
pinMode(LED,OUTPUT);
pinMode(Button,INPUT);
}
void loop() {
//ボタンが押されたかを"val"という名前でを管理しています。
val = digitalRead(Button);
//HIGHは押されているということになります。ちなみに、OUTPUTでは約5V程度の電気が流れます。
//ifとelseは「もし〜なら」「そうでないなら」という意味です。Scratchにもありますね。
if(val==HIGH){
digitalWrite(LED,HIGH);
}
else{
digitalWrite(LED,LOW);
}
}
| 20.37037
| 83
| 0.725455
|
020d124eb733e096345536343faa753d2ba41b03
| 815
|
ino
|
Arduino
|
arduino/ArduinoPusherTest_public_room/RobotExample/RobotExample.ino
|
spoymenov/arisgames
|
aad5f5c6cdb3b1e8ade68da012c6e46ac9a6f77c
|
[
"MIT"
] | 1
|
2018-12-25T15:19:12.000Z
|
2018-12-25T15:19:12.000Z
|
arduino/ArduinoPusherTest_public_room/RobotExample/RobotExample.ino
|
augustozuniga/arisgames
|
1ccf8fcbd9083134972b80e429456dbd6e28aa3d
|
[
"MIT"
] | null | null | null |
arduino/ArduinoPusherTest_public_room/RobotExample/RobotExample.ino
|
augustozuniga/arisgames
|
1ccf8fcbd9083134972b80e429456dbd6e28aa3d
|
[
"MIT"
] | null | null | null |
#include <SPI.h>
#include <Ethernet.h>
#include <PusherClient.h>
byte mac[] = { 0xAB, 0xCD, 0xE2, 0xFF, 0xFE, 0xED };
PusherClient client;
void setup() {
Serial.begin(9600);
Serial.println("Setup...");
if (Ethernet.begin(mac) == 0) {
Serial.println("Init Ethernet failed");
while(1);
}
else
Serial.println("Init Ethernet Success!");
if(client.connect("79f6a265dbb7402a49c9")) {
client.bindAll(eventHandler);
client.subscribe("public-pusher_room_channel");
Serial.println("Pusher Connect Success!");
}
else {
Serial.println("Pusher Connect failed");
while(1);
}
}
void loop() {
if (client.connected()) {
client.monitor();
}
else {
Serial.println("Client Disconnected... :(");
}
}
void eventHandler(String data) {
Serial.println("Event!");
}
| 19.878049
| 52
| 0.640491
|
253223b1a13160801d885d19a6062eb8ee61dabf
| 1,020
|
ino
|
Arduino
|
examples/Lab.02.Sensors/BasicDataProcessing/BasicDataProcessing.ino
|
erikmwerner/slas2022
|
c8f6cedb0b1ef85c35f012638b41847bf771453b
|
[
"MIT"
] | null | null | null |
examples/Lab.02.Sensors/BasicDataProcessing/BasicDataProcessing.ino
|
erikmwerner/slas2022
|
c8f6cedb0b1ef85c35f012638b41847bf771453b
|
[
"MIT"
] | null | null | null |
examples/Lab.02.Sensors/BasicDataProcessing/BasicDataProcessing.ino
|
erikmwerner/slas2022
|
c8f6cedb0b1ef85c35f012638b41847bf771453b
|
[
"MIT"
] | null | null | null |
/*
Basic Data Processing
Reads an analog input on pin 0, prints the result to the Serial Monitor.
Graphical representation is available using Serial Plotter (Tools > Serial Plotter menu).
Attach the center node of a voltage divider circuit to pin A0, and the outside nodes to +3.3V and ground.
This example sketch has been modified from the example code at:
http://www.arduino.cc/en/Tutorial/AnalogReadSerial
*/
// the setup routine runs once when you press reset:
void setup() {
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
}
// the loop routine runs over and over again forever:
void loop() {
int sensorValue = analogRead(A0); // read the input on analog pin 0:
double intensity = map(sensorValue,11,926,0,100); // scale the value to relative light intensity (0 - 100%)
Serial.println(intensity); // print out the value you read:
int delayTimeMs = 10; // 10ms delay ~= 100 Hz sampling
delay(delayTimeMs); // delay in between reads for stability
}
| 36.428571
| 109
| 0.731373
|
875d2a07c284c7fcf86a034e4c3515d68e8046b8
| 1,688
|
ino
|
Arduino
|
microcontroller/sensors/all/publisher_sensors/publisher_sensors.ino
|
Jasenka11/notelab-code
|
6ad6c276e0f5a0bf65f07331b73bd04f9a8f6223
|
[
"MIT"
] | null | null | null |
microcontroller/sensors/all/publisher_sensors/publisher_sensors.ino
|
Jasenka11/notelab-code
|
6ad6c276e0f5a0bf65f07331b73bd04f9a8f6223
|
[
"MIT"
] | null | null | null |
microcontroller/sensors/all/publisher_sensors/publisher_sensors.ino
|
Jasenka11/notelab-code
|
6ad6c276e0f5a0bf65f07331b73bd04f9a8f6223
|
[
"MIT"
] | 1
|
2022-01-26T11:09:13.000Z
|
2022-01-26T11:09:13.000Z
|
#include "MqttClient.h"
#include "WifiClient.h"
#include "HCSR04.h"
#include "PIR.h"
#include "DHT.h"
#include <ArduinoJson.h>
char *ssid_wifi = "netw0";
char *pass_wifi = "password1";
const char *mqtt_broker_ip = "192.168.1.3";
const int mqtt_broker_port = 1883;
const char* client_id = "publisher_sensors";
char* temp_topic = "temp_topic";
char* dist_topic = "dist_topic";
char* motion_topic = "motion_topic";
WifiClient wifi_client(ssid_wifi, pass_wifi);
MqttClient mqtt_client(mqtt_broker_ip, mqtt_broker_port);
#define DHTPIN 3 //specify DHT11's pin
#define DHTTYPE DHT11 // DHT11's type
DHT dht(DHTPIN, DHT11);
HCSR04 hcsr04(1, 2); // specify HC-SR04 trig and echo pins
PIR pir(7); // specify PIR's pin
DynamicJsonDocument temp_doc(1024), dist_doc(1024), motion_doc(1024);
void setup(){
Serial.begin(115200);
wifi_client.connect();
mqtt_client.connect(client_id);
dht.begin(); // initialize the sensor
}
void loop(){
mqtt_client.check_connection(client_id);
float temperature = dht.readTemperature();
if (!isnan(temperature)){
temp_doc["id"] = client_id;
temp_doc["temperature"] = temperature;
}
int distance = hcsr04.calculate_distance();
dist_doc["id"] = client_id, dist_doc["distance"] = distance;
bool is_motion = pir.detect_motion();
motion_doc["id"] = client_id, motion_doc["motion"] = is_motion;
char temp_out[500], dist_out[500], motion_out[500];
serializeJson(temp_doc, temp_out);
serializeJson(dist_doc, dist_out);
serializeJson(motion_doc, motion_out);
mqtt_client.publish_message(temp_topic, temp_out);
mqtt_client.publish_message(dist_topic, dist_out);
mqtt_client.publish_message(motion_topic, motion_out);
}
| 31.259259
| 69
| 0.738744
|
ab3ce2e63d9116f7e58707f2a9826f2360821032
| 1,011
|
ino
|
Arduino
|
examples/6_Make_your_own_runable_classes/5_Blinker_using_fullMachineGen/5_Blinker_using_fullMachineGen.ino
|
bricoleau/easyRun
|
5866985d4c9b6045833d7ad162e074ffa4e2d93b
|
[
"MIT"
] | 1
|
2022-01-16T14:07:14.000Z
|
2022-01-16T14:07:14.000Z
|
examples/6_Make_your_own_runable_classes/5_Blinker_using_fullMachineGen/5_Blinker_using_fullMachineGen.ino
|
AR17HY/easyRun
|
5866985d4c9b6045833d7ad162e074ffa4e2d93b
|
[
"MIT"
] | null | null | null |
examples/6_Make_your_own_runable_classes/5_Blinker_using_fullMachineGen/5_Blinker_using_fullMachineGen.ino
|
AR17HY/easyRun
|
5866985d4c9b6045833d7ad162e074ffa4e2d93b
|
[
"MIT"
] | 1
|
2022-01-11T13:50:53.000Z
|
2022-01-11T13:50:53.000Z
|
#include "easyRun.h"
class blinker : public fullMachineGen
{
private :
int _pin;
unsigned long _delay_ms;
public :
blinker(int pin, long delay_ms)
{
_pin = pin;
_delay_ms = delay_ms;
}
protected :
void println(const char *msg)
{
Serial.print(millis());
Serial.print(", pin");
Serial.print(_pin);
Serial.print(' ');
Serial.println(msg);
}
void init()
{
println("init");
pinMode(_pin, OUTPUT);
next(&blinker::high);
}
void high()
{
println("HIGH");
digitalWrite(_pin, HIGH);
next(&blinker::low, _delay_ms);
}
void low()
{
println("LOW");
digitalWrite(_pin, LOW);
next(&blinker::high, _delay_ms);
}
};
//Using a class allows to handle several blinkers
blinker a(3, 2000);
blinker b(LED_BUILTIN, 1000);
void setup()
{
Serial.begin(115200);
}
void loop()
{
easyRun();
}
| 16.306452
| 51
| 0.526212
|
cedab3d136c5b519bba2f49580690f8efca43efb
| 2,335
|
ino
|
Arduino
|
C++ Library/ESP32 DevkitC/Controlling_DC_Motor_with_L298/Controlling_DC_Motor_with_DriverL298.ino
|
hammad1201/Hacktoberfest-2021
|
b4b86792755c7b86d5bcc94ac8159d8825ed169e
|
[
"MIT"
] | 27
|
2020-10-19T10:45:34.000Z
|
2021-10-16T13:02:59.000Z
|
C++ Library/ESP32 DevkitC/Controlling_DC_Motor_with_L298/Controlling_DC_Motor_with_DriverL298.ino
|
hammad1201/Hacktoberfest-2021
|
b4b86792755c7b86d5bcc94ac8159d8825ed169e
|
[
"MIT"
] | 165
|
2020-10-19T08:49:46.000Z
|
2021-10-19T05:14:28.000Z
|
C++ Library/ESP32 DevkitC/Controlling_DC_Motor_with_L298/Controlling_DC_Motor_with_DriverL298.ino
|
hammad1201/Hacktoberfest-2021
|
b4b86792755c7b86d5bcc94ac8159d8825ed169e
|
[
"MIT"
] | 82
|
2020-10-19T08:16:33.000Z
|
2021-10-19T05:31:03.000Z
|
#include "Arduino.h"
#include "DCMDriverL298.h"
// Pin Definitions
#define DCMOTORDRIVERL298_PIN_INT1 0
#define DCMOTORDRIVERL298_PIN_ENB 3
#define DCMOTORDRIVERL298_PIN_INT2 2
#define DCMOTORDRIVERL298_PIN_ENA 1
#define DCMOTORDRIVERL298_PIN_INT3 4
#define DCMOTORDRIVERL298_PIN_INT4 5
DCMDriverL298 dcMotorDriverL298(DCMOTORDRIVERL298_PIN_ENA,DCMOTORDRIVERL298_PIN_INT1,DCMOTORDRIVERL298_PIN_INT2,DCMOTORDRIVERL298_PIN_ENB,DCMOTORDRIVERL298_PIN_INT3,DCMOTORDRIVERL298_PIN_INT4);
// define vars for testing menu
const int timeout = 10000; //define timeout of 10 sec
char menuOption = 0;
long time0;
// Setup the essentials for your circuit to work. It runs first every time your circuit is powered with electricity.
void setup()
{
// Setup Serial which is useful for debugging
// Use the Serial Monitor to view printed messages
Serial.begin(9600);
while (!Serial) ; // wait for serial port to connect. Needed for native USB
Serial.println("start");
menuOption = menu();
}
// Main logic of your circuit. It defines the interaction between the components you selected. After setup, it runs over and over again, in an eternal loop.
void loop()
{
if(menuOption == '1') {
dcMotorDriverL298.setMotorA(200,1);
dcMotorDriverL298.setMotorB(200,0);
delay(2000);
//Stop both motors
dcMotorDriverL298.stopMotors();
delay(2000);
}
if (millis() - time0 > timeout)
{
menuOption = menu();
}
}
char menu()
{
Serial.println(F("\nWhich component would you like to test?"));
Serial.println(F("(1) L298N Motor Driver with Dual Hobby DC motors"));
Serial.println(F("(menu) send anything else or press on board reset button\n"));
while (!Serial.available());
// Read data from serial monitor if received
while (Serial.available())
{
char c = Serial.read();
if (isAlphaNumeric(c))
{
if(c == '1')
Serial.println(F("Now Testing L298N Motor Driver with Dual Hobby DC motors"));
else
{
Serial.println(F("illegal input!"));
return 0;
}
time0 = millis();
return c;
}
}
}
| 28.82716
| 194
| 0.637687
|
4f6c82de6a14c57cda5a0512fdb4346008eb618d
| 3,669
|
ino
|
Arduino
|
BryanJ_initial.cpp.ino
|
opensource-lgpl-gpl/team17-asu
|
9412d42261517fb352580195f58f18ddd147c983
|
[
"MIT"
] | null | null | null |
BryanJ_initial.cpp.ino
|
opensource-lgpl-gpl/team17-asu
|
9412d42261517fb352580195f58f18ddd147c983
|
[
"MIT"
] | null | null | null |
BryanJ_initial.cpp.ino
|
opensource-lgpl-gpl/team17-asu
|
9412d42261517fb352580195f58f18ddd147c983
|
[
"MIT"
] | 1
|
2021-02-18T03:34:10.000Z
|
2021-02-18T03:34:10.000Z
|
////////////////////////////////////////////////////////////////////////
////////////////////Author: Bryan Jiron/////////////////////////////////
////////////////////////////////////////////////////////////////////////
// UPDATES:
// 1.Create Loop to run from 0-14 m/ft to show the
// serial monitor as a video for the presentation
#include <Adafruit_NeoPixel.h>
#include <LiquidCrystal.h>
#define LED_PIN 8
#define TRIGGER_PIN 13
#define SONAR_ECHO_PIN 7
#define CAUTION_LED_COUNT 4
#define DANGER_LED_COUNT 8
#define SPEED_OF_SOUND_IPUS 0.0135039
#define DELAY_MS 10
#define RED 255
LiquidCrystal Display(12, 11, 5, 4, 3, 2); // LCD interface pins
Adafruit_NeoPixel Caution_Pixels = Adafruit_NeoPixel(
CAUTION_LED_COUNT,
LED_PIN,
NEO_GRB + NEO_KHZ800
);
Adafruit_NeoPixel Danger_Pixels = Adafruit_NeoPixel(
DANGER_LED_COUNT,
LED_PIN,
NEO_GRB + NEO_KHZ800
);
long now,
last_now,
time_traveled_in_ms,
speed_of_trailing_car,
last_distance_ft,
distance_traveled_ft,
sonar_echo_duration;
float distance_inches,
speed_fps,
distance_ft;
int testbenchVAR=1; // 3 states 0=off, 1=Caution, 2=STOP
void setup() {
Caution_Pixels.begin();
Danger_Pixels.begin();
Display.begin(16, 1); //(col,rows)
pinMode(TRIGGER_PIN, OUTPUT);
pinMode(SONAR_ECHO_PIN, INPUT);
Serial.begin(9600);
}
void loop() {
//Reset Trigger
digitalWrite(TRIGGER_PIN, LOW);
delayMicroseconds(2);
digitalWrite(TRIGGER_PIN, HIGH);
delayMicroseconds(DELAY_MS); //10us is required trigger input
////////////////////////////////////////////////////////////////////////
////////////////////First compute the distance//////////////////////////
////////////////////////////////////////////////////////////////////////
//Compute Distance
sonar_echo_duration= pulseIn(SONAR_ECHO_PIN, HIGH); //in ms, 2way
distance_inches=sonar_echo_duration*SPEED_OF_SOUND_IPUS/2;
distance_ft = distance_inches/12;
if (distance_ft > 14) return;
//Compute Speed
now = millis();
last_now = now;
time_traveled_in_ms = now - last_now;
last_distance_ft = distance_ft;
distance_traveled_ft = last_distance_ft - distance_ft;
if (distance_traveled_ft < 0) return;
speed_fps = distance_traveled_ft / (time_traveled_in_ms / 1000);
//Display in serial monitor what the distance and speed
Serial.print("Distance: ");
Serial.println(distance_ft);
Serial.print("Speed: ");
Serial.println(speed_of_trailing_car);
////////////////////////////////////////////////////////////////////////
///////////////////////////Decision Diamonds////////////////////////////
////////////////////////////////////////////////////////////////////////
//IF statements
if (distance_ft <= 6 && speed_fps>0){
for (int i=0; i < CAUTION_LED_COUNT; i++) {
// Caution_pixels.Color takes RGB values, from 0,0,0 up to 255,255,255
Caution_Pixels.setPixelColor(i, Caution_Pixels.Color(RED, 0, 0));
// This sends the updated pixel color to the hardware.
Caution_Pixels.show();
// Delay for a period of time (in milliseconds).
delay(DELAY_MS);
Display.print(" !CAUTION! ");
}
}
if (distance_ft >= 14 && distance_ft<=14 && speed_fps>5){
for (int i=0; i < DANGER_LED_COUNT; i++) {
// Danger_pixels.Color takes RGB values, from 0,0,0 up to 255,255,255
Danger_Pixels.setPixelColor(i, Danger_Pixels.Color(RED, 0, 0));
// This sends the updated pixel color to the hardware.
Danger_Pixels.show();
// Delay for a period of time (in milliseconds).
delay(DELAY_MS);
Display.print(" !!STOP!! ");
}
}
}
| 28.007634
| 74
| 0.58272
|
4465373482869dba3ab4130fb2a01095a2ee728e
| 690
|
ino
|
Arduino
|
Prueba_tiempo_espera/Prueba_tiempo_espera.ino
|
miguel5612/Monitor_de_gabinetes_electricos
|
6e0124ea54c5cf5b32c40e192668d13748d2525a
|
[
"MIT"
] | null | null | null |
Prueba_tiempo_espera/Prueba_tiempo_espera.ino
|
miguel5612/Monitor_de_gabinetes_electricos
|
6e0124ea54c5cf5b32c40e192668d13748d2525a
|
[
"MIT"
] | null | null | null |
Prueba_tiempo_espera/Prueba_tiempo_espera.ino
|
miguel5612/Monitor_de_gabinetes_electricos
|
6e0124ea54c5cf5b32c40e192668d13748d2525a
|
[
"MIT"
] | null | null | null |
boolean estadoLed = false; //guarda el estado del led (encendido o apagado)
unsigned long periodo = 30*1000; // tiempo que esta el LED en alto y bajo
unsigned long tiempoAnterior = 0; //guarda tiempo de referencia para comparar
void setup() {
pinMode(13,OUTPUT); //configura la salida
}
void loop() {
ControlEspera(periodo, 1);
}
void ControlEspera(unsigned long Pausa, int numPuerta)
{
if(millis()-tiempoAnterior>=Pausa){ //si ha transcurrido el periodo programado
estadoLed=!estadoLed; //cambia el estado del led cada 100ms
digitalWrite(13,estadoLed); //actualiza el estado del led
tiempoAnterior=millis(); //guarda el tiempo actual como referencia
}
}
| 28.75
| 81
| 0.724638
|
184db96c4a40cb1722dce3da9842321e6e894195
| 1,511
|
ino
|
Arduino
|
3ayina/UI.ino
|
ademdj19/3yina_project
|
b08256916ebd9848086a85c4885c48937849d749
|
[
"BSD-3-Clause"
] | null | null | null |
3ayina/UI.ino
|
ademdj19/3yina_project
|
b08256916ebd9848086a85c4885c48937849d749
|
[
"BSD-3-Clause"
] | null | null | null |
3ayina/UI.ino
|
ademdj19/3yina_project
|
b08256916ebd9848086a85c4885c48937849d749
|
[
"BSD-3-Clause"
] | null | null | null |
#include "Arduino.h"
#include "UI.h"
/*--| UI class responsible for displaying scenes respectively |--*/
UI::UI() {
return;
};
void UI::lcd_dht_master() {
/*--| DHT master lcd scene |--*/
lcd.clear();
lcd.setCursor(0, 0);
lcd.println("<DHT1");
lcd.print(" T="+String(desired_temp,1));
lcd.setCursor(15,0);
lcd.print(">");
lcd.setCursor(0, 1);
lcd.print(temp_Master, 2);
lcd.print("C|");
lcd.print(hum_Master, 2);
lcd.print("%");
};
void UI::lcd_dht_slave() {
/*--| DHT slave lcd scene |--*/
lcd.clear();
lcd.setCursor(0, 0);
lcd.println("<DHT2");
lcd.print(" T="+String(desired_temp,1));
lcd.setCursor(15,0);
lcd.print(">");
lcd.setCursor(0, 1);
lcd.print(temp_Slave, 2);
lcd.print("C|");
lcd.print(hum_Slave, 2);
lcd.print("%");
};
void UI::lcd_period() {
/*--| Period setting scene |--*/
lcd.clear();
lcd.setCursor(0, 0);
lcd.println("<PERIOD >");
lcd.setCursor(0, 1);
lcd.print("T=");
lcd.print(period);
lcd.print(" s");
};
void UI::lcd_mass() {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("<MASS ");
lcd.print(String(mass_in_g, 2) + " g");
lcd.setCursor(15, 0);
lcd.print(">");
lcd.setCursor(0,1);
lcd.print(final_mass);
lcd.print(" g");
}
void UI::lcd_start_cycle() {
lcd.clear();
lcd.setCursor(0,0);
lcd.println("<"+press_up+" >");
lcd.setCursor(0,1);
lcd.println(to_start);
}
// typedef for class function
typedef void (UI::*GeneralFunction) ();
static const GeneralFunction doActionsArray [5];
| 21.898551
| 67
| 0.600927
|
17a2ef5d966705fc820a7b015185619d69bc0b6c
| 3,010
|
ino
|
Arduino
|
examples/Advanced/WIFI/WiFiTCP/WiFiTCP.ino
|
aaly/M5StickC-Plus
|
a509d3e4799bebbb3787c2f32a082767f817f260
|
[
"MIT"
] | 138
|
2020-07-16T22:22:30.000Z
|
2022-03-25T08:52:34.000Z
|
examples/Advanced/WIFI/WiFiTCP/WiFiTCP.ino
|
aaly/M5StickC-Plus
|
a509d3e4799bebbb3787c2f32a082767f817f260
|
[
"MIT"
] | 22
|
2020-09-24T12:40:10.000Z
|
2022-03-27T12:23:31.000Z
|
examples/Advanced/WIFI/WiFiTCP/WiFiTCP.ino
|
aaly/M5StickC-Plus
|
a509d3e4799bebbb3787c2f32a082767f817f260
|
[
"MIT"
] | 47
|
2020-07-16T22:22:19.000Z
|
2022-03-07T10:26:22.000Z
|
/*
*******************************************************************************
* Copyright (c) 2021 by M5Stack
* Equipped with M5StickC-Plus sample source code
* 配套 M5StickC-Plus 示例源代码
* Visit the website for more information:https://docs.m5stack.com/en/core/m5stickc_plus
* 获取更多资料请访问:https://docs.m5stack.com/zh_CN/core/m5stickc_plus
*
* describe:WIFI TCP.
* date:2021/9/18
*******************************************************************************
M5StickCPlus will sends a message to a TCP server
M5StickCPlus 将向TCP服务器发送一条数据
*/
#include <M5StickCPlus.h>
#include <WiFi.h>
#include <WiFiMulti.h>
// Set the name and password of the wifi to be connected. 配置所连接wifi的名称和密码
const char *ssid = "cam";
const char *password = "12345678";
WiFiMulti WiFiMulti;
void setup()
{
int sum=0;
M5.begin();
M5.Lcd.setRotation(3); //Rotate the screen. 旋转屏幕
WiFiMulti.addAP(ssid, password); //Add wifi configuration information. 添加wifi配置信息
M5.lcd.printf("Waiting connect to WiFi: %s ...",ssid); //Serial port output format string. 串口输出格式化字符串
while(WiFiMulti.run() != WL_CONNECTED) { //If the connection to wifi is not established successfully. 如果没有与wifi成功建立连接
M5.lcd.print(".");
delay(1000);
sum+=1;
if(sum==8) M5.lcd.print("Conncet failed!");
}
M5.lcd.println("\nWiFi connected");
M5.lcd.print("IP address: ");
M5.lcd.println(WiFi.localIP()); //The serial port outputs the IP address of the M5StickC. 串口输出M5StickC的IP地址
delay(500);
}
void loop()
{
M5.lcd.setCursor(0,40);
const char * host = "www.baidu.com"; //Set the IP address or DNS of the TCP server. 设置TCP服务器的ip或dns
const uint16_t port = 80; //The port of the TCP server is specified. 设置TCP服务器的端口
M5.lcd.printf("Connecting to: %s\n",host);
WiFiClient client;
if (!client.connect(host, port)) { //Connect to the server. 0 is returned if the connection fails. 连接服务器,若连接失败返回0
M5.lcd.print("Connection failed.\nWaiting 5 seconds before retrying...\n");
delay(5000);
return;
}
//send an arbitrary string to the server. 发送一个字符串到上边连接的服务器
client.print("Send this data to the server");
//send a basic document request to the server. 向服务器发送一个基本的文档请求.
client.print("GET /index.html HTTP/1.1\n\n");
int maxloops = 0;
//wait for the server's reply to become available
//等待服务器的回复
while (!client.available() && maxloops < 1000){
maxloops++;
delay(1); //delay 1 msec
}
if (client.available() > 0){ //Detects whether data is received. 检测是否接收到数据
String line = client.readStringUntil('\r'); //Read information from data received by the device until \r is read. 从设备接收到的数据中读取信息,直至读取到\r时
M5.lcd.println(line); //String received by serial port output. 串口输出接收到的字符串
}else{
M5.lcd.println("client.available() timed out ");
}
M5.lcd.println("Closing connection.");
client.stop();
M5.lcd.println("Waiting 5 seconds before restarting...");
delay(5000);
M5.lcd.fillRect(0,40,320,220,BLACK);
}
| 37.625
| 142
| 0.652492
|
27be84788c14195155d04ed2e745231dcdb9e79d
| 8,569
|
ino
|
Arduino
|
led_usb/led_usb.ino
|
math85360/arduino_neopixels_tests
|
9f7d9e607aed48787ec7cc049f18d800a5b27f60
|
[
"Apache-2.0"
] | null | null | null |
led_usb/led_usb.ino
|
math85360/arduino_neopixels_tests
|
9f7d9e607aed48787ec7cc049f18d800a5b27f60
|
[
"Apache-2.0"
] | null | null | null |
led_usb/led_usb.ino
|
math85360/arduino_neopixels_tests
|
9f7d9e607aed48787ec7cc049f18d800a5b27f60
|
[
"Apache-2.0"
] | null | null | null |
//#include <PololuLedStrip.h>
/* This is AVR code for driving the RGB LED strips from Pololu.
It allows complete control over the color of an arbitrary number of LEDs.
This implementation disables interrupts while it does bit-banging with inline assembly.
*/
/* This line specifies the frequency your AVR is running at.
This code supports 20 MHz and 16 MHz. */
#define F_CPU 16000000
// These lines specify what pin the LED strip is on.
// You will either need to attach the LED strip's data line to PC0 or change these
// lines to specify a different pin.
#define LED_STRIP_PORT PORTD
#define LED_STRIP_DDR DDRD
#define LED_STRIP_PIN 7
#include <avr/io.h>
#include <avr/interrupt.h>
#include <util/delay.h>
#include <math.h>
/** The rgb_color struct represents the color for an 8-bit RGB LED.
Examples:
Black: (rgb_color){ 0, 0, 0 }
Pure red: (rgb_color){ 255, 0, 0 }
Pure green: (rgb_color){ 0, 255, 0 }
Pure blue: (rgb_color){ 0, 0, 255 }
White: (rgb_color){ 255, 255, 255} */
typedef struct rgb_color
{
unsigned char red, green, blue;
} rgb_color;
/** led_strip_write sends a series of colors to the LED strip, updating the LEDs.
The colors parameter should point to an array of rgb_color structs that hold the colors to send.
The count parameter is the number of colors to send.
ff
This function takes less than 2 ms to update 30 LEDs.
Interrupts must be disabled during that time, so any interrupt-based library
can be negatively affected by this function.
Timing details at 20 MHz (the numbers slightly different at 16 MHz):
0 pulse = 700 ns
1 pulse = 1300 ns
"period" = 2500 ns
*/
void __attribute__((noinline)) led_strip_write(rgb_color * colors, unsigned int count)
{
// Set the pin to be an output driving low.
LED_STRIP_PORT &= ~(1<<LED_STRIP_PIN);
LED_STRIP_DDR |= (1<<LED_STRIP_PIN);
cli(); // Disable interrupts temporarily because we don't want our pulse timing to be messed up.
while(count--)
{
// Send a color to the LED strip.
// The assembly below also increments the 'colors' pointer,
// it will be pointing to the next color at the end of this loop.
asm volatile(
"rcall send_led_strip_byte%=\n" // Send red component.
"rcall send_led_strip_byte%=\n" // Send green component.
"rcall send_led_strip_byte%=\n" // Send blue component.
"rjmp led_strip_asm_end%=\n" // Jump past the assembly subroutines.
// send_led_strip_byte subroutine: Sends a byte to the LED strip.
"send_led_strip_byte%=:\n"
"ld __tmp_reg__, %a0+\n" // Read the next color brightness byte and advance the pointer
"rcall send_led_strip_bit%=\n" // Send most-significant bit (bit 7).
"rcall send_led_strip_bit%=\n"
"rcall send_led_strip_bit%=\n"
"rcall send_led_strip_bit%=\n"
"rcall send_led_strip_bit%=\n"
"rcall send_led_strip_bit%=\n"
"rcall send_led_strip_bit%=\n"
"rcall send_led_strip_bit%=\n" // Send least-significant bit (bit 0).
"ret\n"
// send_led_strip_bit subroutine: Sends single bit to the LED strip by driving the data line
// high for some time. The amount of time the line is high depends on whether the bit is 0 or 1,
// but this function always takes the same time (2 us).
"send_led_strip_bit%=:\n"
"sbi %2, %3\n" // Drive the line high.
"rol __tmp_reg__\n" // Rotate left through carry.
#if F_CPU == 16000000
"nop\n" "nop\n" "nop\n" "nop\n" "nop\n"
"nop\n" "nop\n"
#elif F_CPU == 20000000
"nop\n" "nop\n" "nop\n" "nop\n" "nop\n"
"nop\n" "nop\n" "nop\n" "nop\n" "nop\n"
#else
#error "Unsupported F_CPU"
#endif
"brcs .+2\n" "cbi %2, %3\n" // If the bit to send is 0, drive the line low now.
#if F_CPU == 16000000
"nop\n" "nop\n" "nop\n" "nop\n" "nop\n"
"nop\n" "nop\n" "nop\n"
#elif F_CPU == 20000000
"nop\n" "nop\n" "nop\n" "nop\n" "nop\n"
"nop\n" "nop\n" "nop\n" "nop\n" "nop\n"
#endif
"brcc .+2\n" "cbi %2, %3\n" // If the bit to send is 1, drive the line low now.
#if F_CPU == 16000000
"nop\n" "nop\n" "nop\n" "nop\n" "nop\n"
"nop\n" "nop\n" "nop\n"
#elif F_CPU == 20000000
"nop\n" "nop\n" "nop\n" "nop\n" "nop\n"
"nop\n" "nop\n" "nop\n" "nop\n" "nop\n"
"nop\n" "nop\n" "nop\n" "nop\n" "nop\n"
#endif
"ret\n"
"led_strip_asm_end%=: "
: "=b" (colors)
: "0" (colors), // %a0 points to the next color to display
"I" (_SFR_IO_ADDR(LED_STRIP_PORT)), // %2 is the port register (e.g. PORTC)
"I" (LED_STRIP_PIN) // %3 is the pin number (0-8)
);
// Uncomment the line below to temporarily enable interrupts between each color.
//sei(); asm volatile("nop\n"); cli();
}
sei(); // Re-enable interrupts now that we are done.
_delay_us(24); // Hold the line low for 15 microseconds to send the reset signal.
}
#define LED_COUNT 60
rgb_color colors[LED_COUNT];
//byte cmd[2];
void setup() {
Serial.begin(768000);
// Serial.write("AT+BAUDC");
//Serial.begin(384000);
// cmd[8]={B0,B0};
setall(255,255,255);
led_strip_write(colors, LED_COUNT);
delay(1000);
// setall(0,0,0);
// led_strip_write(colors, LED_COUNT);
}
int pos;
int pos2;
int c_r;
int c_g;
int c_b;
int cols[8];
void loop()
{
if(Serial.available()){
int c=Serial.read();
switch(c){
case 'S':
pos=-1;
break;
case 'U':
setcolrgb(cols[0],cols[1],cols[2]*16+cols[3],cols[4]*16+cols[5],cols[6]*16+cols[7]);
break;
case 'V':
setpartrgb(cols[1],10,cols[2]*16+cols[3],cols[4]*16+cols[5],cols[6]*16+cols[7]);
break;
case 'W':
setrgbparts(cols[0]*16+cols[1],cols[2]*16+cols[3],cols[4]*16+cols[5]);
break;
case 'X':
colors[cols[0]*16+cols[1]]=(rgb_color){cols[2]*16+cols[3],cols[4]*16+cols[5],cols[6]*16+cols[7]};
break;
case 'Y':
setall(cols[0]*16+cols[1],cols[2]*16+cols[3],cols[4]*16+cols[5]);
break;
case 'Z':
led_strip_write(colors, LED_COUNT);
break;
case '0':
cols[pos]=0;
break;
case '1':
cols[pos]=1;
break;
case '2':
cols[pos]=2;
break;
case '3':
cols[pos]=3;
break;
case '4':
cols[pos]=4;
break;
case '5':
cols[pos]=5;
break;
case '6':
cols[pos]=6;
break;
case '7':
cols[pos]=7;
break;
case '8':
cols[pos]=8;
break;
case '9':
cols[pos]=9;
break;
case 'A':
cols[pos]=10;
break;
case 'B':
cols[pos]=11;
break;
case 'C':
cols[pos]=12;
break;
case 'D':
cols[pos]=13;
break;
case 'E':
cols[pos]=14;
break;
case 'F':
cols[pos]=15;
break;
default:
pos-=1;
}
pos+=1;
if(pos>8) {
pos=8;
}
// colors[0]=(rgb_color){255, 0, 0};
// led_strip_write(colors, LED_COUNT);
}
}
void setall(int r, int g, int b){
rgb_color v=(rgb_color){r, g, b};
for(int i=0;i<LED_COUNT;i++){
colors[i]=v;
}
}
void setpartrgb(int part,int sizepart,int r, int g, int b){
rgb_color v=(rgb_color){r, g, b};
int k=part*sizepart+sizepart;
for(int i=part*sizepart;i<k;i++){
colors[i]=v;
}
}
void setrgbparts(int r, int g, int b){
//int k=LED_COUNT/6;
setpartrgb(0,10,r,0,0);
setpartrgb(1,10,0,g,0);
setpartrgb(2,10,0,0,b);
setpartrgb(3,10,0,0,b);
setpartrgb(4,10,0,g,0);
setpartrgb(5,10,r,0,0);
}
void setcolrgb(int mode, int p,int r, int g, int b){
rgb_color black=(rgb_color){0,0,0};
rgb_color v=(rgb_color){r, g, b};
if(mode==0){
for(int i=0;i<LED_COUNT/2;i++){
if(i<p){
colors[i]=v;
colors[LED_COUNT-i-1]=v;
}else{
colors[i]=black;
colors[LED_COUNT-i-1]=black;
}
}
}
if(mode==1){
for(int i=0;i<LED_COUNT/4;i++){
if(i<p){
colors[14-i]=v;
colors[14+i]=v;
colors[44-i]=v;
colors[44+i]=v;
}else{
colors[14-i]=black;
colors[14+i]=black;
colors[44-i]=black;
colors[44+i]=black;
}
}
}
}
| 29.047458
| 105
| 0.567161
|
c795fb443c79101975e5b635ad40316f1555b6eb
| 329
|
ino
|
Arduino
|
LCD-first/LCD-first.ino
|
JulianNicholls/Prev-Arduino
|
31b56ec97d8f7e98e0b70a95f1eebaffa2ce9bd9
|
[
"MIT"
] | 2
|
2021-03-06T06:09:44.000Z
|
2021-08-01T01:46:46.000Z
|
LCD-first/LCD-first.ino
|
JulianNicholls/Prev-Arduino
|
31b56ec97d8f7e98e0b70a95f1eebaffa2ce9bd9
|
[
"MIT"
] | null | null | null |
LCD-first/LCD-first.ino
|
JulianNicholls/Prev-Arduino
|
31b56ec97d8f7e98e0b70a95f1eebaffa2ce9bd9
|
[
"MIT"
] | null | null | null |
#include <Servo.h>
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
void setup() {
// put your setup code here, to run once:
lcd.begin(20, 4);
lcd.print("Set Up");
}
void loop() {
// put your main code here, to run repeatedly:
lcd.setCursor(0, 1);
lcd.print(millis() / 1000);
delay(500);
}
| 14.304348
| 48
| 0.613982
|
49bcb36680e3cc46d9cb552350226f628154f33e
| 3,711
|
ino
|
Arduino
|
PowerTrial.ino
|
Sowmiao/LPWESNIOT
|
c3a014ea8c8218cc2ca7536610146d704f81b936
|
[
"Unlicense"
] | null | null | null |
PowerTrial.ino
|
Sowmiao/LPWESNIOT
|
c3a014ea8c8218cc2ca7536610146d704f81b936
|
[
"Unlicense"
] | null | null | null |
PowerTrial.ino
|
Sowmiao/LPWESNIOT
|
c3a014ea8c8218cc2ca7536610146d704f81b936
|
[
"Unlicense"
] | null | null | null |
#include <avr/sleep.h>
#include <avr/power.h>
#include <DHT.h>
#define DHTPIN 3
#define DHTTYPE DHT11
DHT dht(DHTPIN,DHTTYPE);
unsigned long lastHT=0;
unsigned long lastSE=0;
void printHT();
int led=13;
int threshold=20;
int volume;
#define LED_PIN (13)
volatile int f_timer=0;
/***************************************************
* Name: ISR(TIMER1_OVF_vect)
*
* Returns: Nothing.
*
* Parameters: None.
*
* Description: Timer1 Overflow interrupt.
*
***************************************************/
ISR(TIMER1_OVF_vect)
{
/* set the flag. */
if(f_timer == 0)
{
f_timer = 1;
}
}
/***************************************************
* Name: enterSleep
*
* Returns: Nothing.
*
* Parameters: None.
*
* Description: Enters the arduino into sleep mode.
*
***************************************************/
void enterSleep(void)
{
set_sleep_mode(SLEEP_MODE_IDLE);
sleep_enable();
/* Disable all of the unused peripherals. This will reduce power
* consumption further and, more importantly, some of these
* peripherals may generate interrupts that will wake our Arduino from
* sleep!
*/
power_adc_disable();
power_spi_disable();
power_timer0_disable();
power_timer2_disable();
power_twi_disable();
/* Now enter sleep mode. */
sleep_mode();
/* The program will continue from here after the timer timeout*/
sleep_disable(); /* First thing to do is disable sleep. */
/* Re-enable the peripherals. */
power_all_enable();
}
/***************************************************
* Name: setup
*
* Returns: Nothing.
*
* Parameters: None.
*
* Description: Setup for the serial comms and the
* timer.
*
***************************************************/
void setup()
{
Serial.begin(9600);
/* Don't forget to configure the pin! */
pinMode(LED_PIN, OUTPUT);
/*** Configure the timer.***/
/* Normal timer operation.*/
TCCR1A = 0x00;
/* Clear the timer counter register.
* You can pre-load this register with a value in order to
* reduce the timeout period, say if you wanted to wake up
* ever 4.0 seconds exactly.
*/
TCNT1=0x0000;
/* Configure the prescaler for 1:1024, giving us a
* timeout of 4.09 seconds.
*/
TCCR1B = 0x05;
/* Enable the timer overlow interrupt. */
TIMSK1=0x01;
}
/***************************************************
* Name: enterSleep
*
* Returns: Nothing.
*
* Parameters: None.
*
* Description: Main application loop.
*
***************************************************/
void loop()
{
if(f_timer==1)
{
f_timer = 0;
/* Toggle the LED */
digitalWrite(LED_PIN, !digitalRead(LED_PIN));
if(millis()-(10*60*1000UL)>lastHT)
{
lastHT=millis();
printHT();
}
if(millis()-(5*60*1000UL)>lastSE)
{
lastSE=millis();
volume=analogRead(A0);
if(volume>=threshold)
{
digitalWrite(led,HIGH);
Serial.println("loud");
}
else
{
digitalWrite(led,LOW);
Serial.println("quiet");
}
Serial.println(volume,DEC);
delay(5000);
}
/* Re-enter sleep mode. */
enterSleep();
}
}
void printHT()
{
float h = dht.readHumidity();
float t = dht.readTemperature();
// Read temperature as Fahrenheit (isFahrenheit = true)
Serial.println("Humidity: % ");
Serial.println(h);
Serial.println("Temperature: celsius");
Serial.println(t);
delay(3000);
if(t>=30)
{
Serial.println("Sunny");
}
else
{
Serial.println("Cloudy");
}
if(h>=70)
{
Serial.println("rainy");
}
else
{
Serial.println("less chances of rain");
}
}
| 17.927536
| 72
| 0.545136
|
a614543c5258d0c465a1a815178394639d9f5428
| 1,175
|
ino
|
Arduino
|
deprecated/sender/sender.ino
|
ithallojunior/data_transmission
|
eaf1ef81c018dc5a42f1756b39e19bfaa7f34ed5
|
[
"MIT"
] | null | null | null |
deprecated/sender/sender.ino
|
ithallojunior/data_transmission
|
eaf1ef81c018dc5a42f1756b39e19bfaa7f34ed5
|
[
"MIT"
] | null | null | null |
deprecated/sender/sender.ino
|
ithallojunior/data_transmission
|
eaf1ef81c018dc5a42f1756b39e19bfaa7f34ed5
|
[
"MIT"
] | null | null | null |
#define CE_PIN 5 //reset pin
#define CSN_PIN 4 //Since we are using 3 pin configuration we will use same pin for both CE and CSN
#define BYTES 20 //max 255
#include "RF24.h"
RF24 radio(CE_PIN, CSN_PIN);
byte data[BYTES+1]; // +1 beacause of the ack
byte address[11] = "SimpleNode";
int payload = 0;
void setup() {
radio.begin(); // Start up the radio
radio.setAutoAck(1); // Ensure autoACK is enabled
radio.setRetries(15,15); // Max delay between retries & number of retries
radio.openWritingPipe(address); // Write to device address 'SimpleNode'
radio.setPayloadSize(BYTES+1); // +1 beacause of the ack
analogReference(INTERNAL);
delay(1000);
data[0] = 'f'; // the ack
}
unsigned long start;
void loop(void){
//for (int i=1; i<(BYTES-1); i+=2){
int i=1;
start = micros();
while(i<(BYTES-1)){
payload = analogRead(3);
if((micros() - start) >= 500){
data[i] = (payload>>8);
data[i+1] = (payload&255);
i += 2;
start = micros();
}
//delayMicroseconds(500); //delay for 2khz
} // in case of error nothing is sent
radio.write( &data, (BYTES+1)*sizeof(byte) ); //Send data to 'Receiver' ever second
}
| 25.543478
| 99
| 0.640851
|
cc15e53d715501b785881b53081e909788de48e1
| 562
|
ino
|
Arduino
|
examples/simple/simple.ino
|
GyverLibs/NecDecoder
|
9efe236cc5e978a3ae17206a765109d5d5681dd6
|
[
"MIT"
] | 2
|
2021-12-09T02:48:10.000Z
|
2021-12-27T14:41:13.000Z
|
examples/simple/simple.ino
|
GyverLibs/NecDecoder
|
9efe236cc5e978a3ae17206a765109d5d5681dd6
|
[
"MIT"
] | 1
|
2022-01-13T20:30:29.000Z
|
2022-01-14T22:08:48.000Z
|
examples/simple/simple.ino
|
GyverLibs/NecDecoder
|
9efe236cc5e978a3ae17206a765109d5d5681dd6
|
[
"MIT"
] | 1
|
2022-01-28T23:13:29.000Z
|
2022-01-28T23:13:29.000Z
|
// приём команд с пульта
// приёмник подключать на прерывание по FALLING
#include <NecDecoder.h>
NecDecoder ir;
void setup() {
Serial.begin(9600);
// подключил на D2, прерывание 0
attachInterrupt(0, irIsr, FALLING);
}
// в прерывании вызываем tick()
void irIsr() {
ir.tick();
}
void loop() {
// если пакет успешно принят
if (ir.available()) {
// выводим весь пакет (32 бита)
Serial.print("0x");
Serial.println(ir.readPacket(), HEX);
// можно вывести только команду (8 бит)
//Serial.println(ir.readCommand(), HEX);
}
}
| 20.071429
| 47
| 0.649466
|
c7359c779430f87eecdbcd81582e0026ef307aaf
| 578
|
ino
|
Arduino
|
Grove - Turbidity Sensor/simplecontrol/simplecontrol.ino
|
Seeed-Studio/Seeed_Learning_Space
|
e3682643f440c8d8b44e534369ae4ed9e5a81b14
|
[
"MIT"
] | 14
|
2020-02-04T08:19:14.000Z
|
2021-12-20T05:56:43.000Z
|
Grove - Turbidity Sensor/simplecontrol/simplecontrol.ino
|
Seeed-Studio/Seeed_Learning_Space
|
e3682643f440c8d8b44e534369ae4ed9e5a81b14
|
[
"MIT"
] | null | null | null |
Grove - Turbidity Sensor/simplecontrol/simplecontrol.ino
|
Seeed-Studio/Seeed_Learning_Space
|
e3682643f440c8d8b44e534369ae4ed9e5a81b14
|
[
"MIT"
] | 7
|
2019-11-28T02:16:18.000Z
|
2021-12-20T05:56:44.000Z
|
int ledPin = 13; // Connect LED on pin 13, or use the onboard one
int sensor_in = 2; // Turbidity sensor on Digital Pin 2
void setup(){
pinMode(ledPin, OUTPUT); // Set ledPin as output mode
pinMode(sensor_in, INPUT); //Set Turbidity sensor pin to input mode
}
void loop(){
if(digitalRead(sensor_in)==LOW){ //Read Touch sensor signal
digitalWrite(ledPin, HIGH); // if Touch sensor is LOW, then turn on
}else{
digitalWrite(ledPin, LOW); // if Touch sensor is HIGH, then turn off the led
}
}
| 36.125
| 87
| 0.612457
|
960c74f33702f8a3d7dff69fbc76825839db564f
| 902
|
ino
|
Arduino
|
test/test.ino
|
jacblo/Arduino
|
be45c5d583ad88f9488f40e2c569164c551dd13e
|
[
"CC0-1.0"
] | 1
|
2021-09-19T18:44:56.000Z
|
2021-09-19T18:44:56.000Z
|
test/test.ino
|
jacblo/Arduino
|
be45c5d583ad88f9488f40e2c569164c551dd13e
|
[
"CC0-1.0"
] | null | null | null |
test/test.ino
|
jacblo/Arduino
|
be45c5d583ad88f9488f40e2c569164c551dd13e
|
[
"CC0-1.0"
] | null | null | null |
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
byte hi[8] = {
B10101,
B10101,
B10101,
B11101,
B10101,
B10101,
B10101,
};
int moveYSense = A0;
int moveXSense = A1;
int moveY = 0;
int moveX = 0;
int tempertures[] = {0,0,0,0};
String cities[] = {"beit shemmesh","jerusalem","rochester","hollywood fl"};
int counter = 0;
int passiveTimer = 0;
void setup() {
lcd.createChar(0, hi);
lcd.begin(16, 2);
lcd.print("weather");
/*
lcd.write(byte(0));
lcd.print(" there");
*/
}
void loop() {
moveY = analogRead(moveXSense);
moveX = analogRead(moveYSense);
if (passiveTimer == 1000){
passiveTimer = 0;
lcd.clear();
lcd.print("hi");
delay(1000);
}
else{
passiveTimer ++;
lcd.clear();
lcd.print("there");
}
/*
else if(digitalRead(7) == HIGH){
lcd.clear();
lcd.print("click");
delay(1000);
}
*/
}
| 15.824561
| 75
| 0.578714
|
12b812a05a5e221044600c16b10f5d5af2a58066
| 294
|
ino
|
Arduino
|
example/Blink/Blink.ino
|
RoseLeBlood/aSTLino
|
99389fa418efd0589815203adad239b91eaad3ea
|
[
"MIT"
] | null | null | null |
example/Blink/Blink.ino
|
RoseLeBlood/aSTLino
|
99389fa418efd0589815203adad239b91eaad3ea
|
[
"MIT"
] | null | null | null |
example/Blink/Blink.ino
|
RoseLeBlood/aSTLino
|
99389fa418efd0589815203adad239b91eaad3ea
|
[
"MIT"
] | null | null | null |
#include <aSTLino.h>
#include <arduino/rgb_strip.hpp>
#include <arduino/stream.hpp>
arduino::digitalOut<13> led;
void setup() {
led.begin();
Serial.begin(9600);
Serial << led.to_string() << endl;
}
void loop() {
led.write(false);
delay(250);
led.write(true);
delay(250);
}
| 14
| 36
| 0.642857
|
567623d661895812ce9f76ed23df573b1d2ba89d
| 2,121
|
ino
|
Arduino
|
midiBrain_LPX/midiBrain_LPX.ino
|
BeatRossmy/MidiBrainModule
|
8bc9693cd826eed7755e2bb22a60386b833f7622
|
[
"MIT"
] | null | null | null |
midiBrain_LPX/midiBrain_LPX.ino
|
BeatRossmy/MidiBrainModule
|
8bc9693cd826eed7755e2bb22a60386b833f7622
|
[
"MIT"
] | null | null | null |
midiBrain_LPX/midiBrain_LPX.ino
|
BeatRossmy/MidiBrainModule
|
8bc9693cd826eed7755e2bb22a60386b833f7622
|
[
"MIT"
] | null | null | null |
#include <EEPROM.h>
#include "MIDI_BRAIN_LPX.h"
elapsedMicros kTimer;
void setup () {
Serial.begin(115200);
initHardware();
delay(600);
usbMIDI.setHandleRealTimeSystem(RealTimeSystem);
// stop all midi messages
for (int n = 0; n < 128; n++) {
MIDI_1.sendNoteOff(n, 0, 1);
MIDI_2.sendNoteOff(n, 0, 1);
MIDI_3.sendNoteOff(n, 0, 1);
MIDI_4.sendNoteOff(n, 0, 1);
}
// TEST CODE LAUNCHPAD X
for (int8_t port=0; port < 4; port++) {
Serial.println(midilist[port]->idProduct());
}
static uint8_t msg [9] = {240, 0, 32, 41, 2, 12, 14, 127, 247};
midilist[0]->sendSysEx(9,msg); // Address hardcoded !!!!! CHANGE
Serial.println("switched to programmer's mode");
static uint8_t msg2 [] = {240, 0, 32, 41, 2, 12, 3, 2, 99, 3, 247};
midilist[0]->sendSysEx(11,msg2);
}
void loop () {
while (usbMIDI.read()) {}
handleExtClock();
handleUSBdevices();
kRate(kTimer);
}
void RealTimeSystem(byte realtimebyte) {
midi_brain.handleClock(realtimebyte);
}
void kRate (elapsedMicros & timer) {
if (timer < 500) return;
timer -= 500;
midi_brain.kRate();
handleHardware();
}
void handleUSBdevices () {
for (int port = 0; port < 4; port++) {
if (midilist[port]->read()) {
led_usb.setOn();
uint8_t type = midilist[port]->getType();
uint8_t data1 = midilist[port]->getData1();
uint8_t data2 = midilist[port]->getData2();
uint8_t channel = midilist[port]->getChannel();
const uint8_t *sys = midilist[port]->getSysExArray();
int idProduct = midilist[port]->idProduct();
midi_brain.handleMIDI(idProduct, type, data1, data2, channel);
}
}
}
void handleExtClock () {
if (MIDI_1.read()) {
byte type = MIDI_1.getType();
if (type == midi::ControlChange) {
uint8_t data1 = MIDI_1.getData1();
uint8_t data2 = MIDI_1.getData2();
uint8_t channel = MIDI_1.getChannel();
midi_brain.handleCC(data1, data2, channel);
return;
}
else if (type == midi::NoteOn) {}
else if (type == midi::NoteOff) {}
else {
midi_brain.handleClock(type);
}
}
}
| 24.662791
| 69
| 0.618576
|
e7f3512c84dececc17168fce1775ad8e5061b527
| 10,986
|
ino
|
Arduino
|
bathroom_light_controller.ino
|
mika-koivusaari/bathroom_light_controller
|
2eec5d5f2e2a9e3062df0a29d74de45768ab5e4e
|
[
"MIT"
] | null | null | null |
bathroom_light_controller.ino
|
mika-koivusaari/bathroom_light_controller
|
2eec5d5f2e2a9e3062df0a29d74de45768ab5e4e
|
[
"MIT"
] | 1
|
2016-11-19T11:35:17.000Z
|
2016-11-19T11:35:17.000Z
|
bathroom_light_controller.ino
|
mika-koivusaari/bathroom_light_controller
|
2eec5d5f2e2a9e3062df0a29d74de45768ab5e4e
|
[
"MIT"
] | null | null | null |
#include <EEPROM.h>
const int LDRPIN=A0;
const int PWM1PIN=9;
const int PWM2PIN=10;
const int PWM3PIN=11;
const int FORCELIGHTPIN=5;
const String GET = "GET";
const String HELP = "HELP";
const String LOAD = "LOAD";
const String SAVE = "SAVE";
const String SET = "SET";
const String SET_LDRDARK = "SET LDRDARK";
const String SET_PWM1LOW = "SET PWM1LOW";
const String SET_PWM1HIGH = "SET PWM1HIGH";
const String SET_PWM2LOW = "SET PWM2LOW";
const String SET_PWM2HIGH = "SET PWM2HIGH";
const String SET_PWM3LOW = "SET PWM3LOW";
const String SET_PWM3HIGH = "SET PWM3HIGH";
const String SET_LOOPDELAY = "SET LOOPDELAY";
const int MAX_CMD_LENGTH = 20;
String inputString = ""; // a string to hold incoming data
boolean stringComplete = false; // whether the string is complete
byte pwm1Goal=0;
byte pwm1Current=0;
byte pwm2Goal=0;
byte pwm2Current=0;
byte pwm3Goal=0;
byte pwm3Current=0;
//value of the LDR
int ldrValue=0;
//value of the force light switch
int forceLightValue=LOW;
//high values of the led strips, read on startup
byte pwm1High=255;
byte pwm2High=255;
byte pwm3High=255;
//low values of the led strips, read on startup
byte pwm1Low=50;
byte pwm2Low=50;
byte pwm3Low=50;
//value of the ldr between dark and light
int ldrDark=800;
int debug=true;
byte loopDelay=50;
//Temporary variable for commands data.
int iTmp=0;
byte bTmp;
void setup() {
// start serial port
Serial.begin(9600);
Serial.println("");
inputString.reserve(MAX_CMD_LENGTH);
readConfig();
printConfig();
//set ldr pin
pinMode(LDRPIN,INPUT);
//set pwm channels
pinMode(PWM1PIN,OUTPUT);
pinMode(PWM2PIN,OUTPUT);
pinMode(PWM3PIN,OUTPUT);
//set forcelight switch input pin
pinMode(FORCELIGHTPIN,INPUT);
}
void loop() {
// print the string when a newline arrives:
if (stringComplete) {
if (inputString==GET) {
Serial.print("Forcelight=");
Serial.println(forceLightValue==HIGH?"HIGH":"LOW");
Serial.print("ldrValue=");
Serial.println(ldrValue);
printConfig();
}
else if (inputString==HELP) {
Serial.println("Commands:");
Serial.println("GET");
Serial.println("SET");
}
else if (inputString==LOAD) {
readConfig();
printConfig();
}
else if (inputString==SAVE) {
writeConfig();
}
else if (inputString.startsWith(SET)) {
set();
} else {
Serial.println("Syntax error:");
Serial.println("Try HELP");
}
// clear the string:
inputString = "";
stringComplete = false;
}
//Read if force light switch is on
forceLightValue=digitalRead(FORCELIGHTPIN);
//Read ldr
ldrValue=analogRead(LDRPIN);
//make light bright if force light is on
if (forceLightValue==HIGH) {
//set pwm goal to high
pwm1Goal=pwm1High;
pwm2Goal=pwm2High;
pwm3Goal=pwm3High;
} else if (ldrValue>ldrDark) { //if hallway if lighted then make lights bright
pwm1Goal=pwm1High;
pwm2Goal=pwm2High;
pwm3Goal=pwm3High;
} else {//otherwise make light dim
pwm1Goal=pwm1Low;
pwm2Goal=pwm2Low;
pwm3Goal=pwm3Low;
}
//advance pwm values to goal
if (pwm1Current>pwm1Goal)
pwm1Current--;
else if (pwm1Current<pwm1Goal)
pwm1Current++;
if (pwm2Current>pwm2Goal)
pwm2Current--;
else if (pwm2Current<pwm2Goal)
pwm2Current++;
if (pwm3Current>pwm3Goal)
pwm3Current--;
else if (pwm3Current<pwm3Goal)
pwm3Current++;
analogWrite(PWM1PIN,pwm1Current);
analogWrite(PWM2PIN,pwm2Current);
analogWrite(PWM3PIN,pwm3Current);
delay(loopDelay);
}
void readConfig() {
//get config versio, 255=no config written
EEPROM.get(0,bTmp);
if (debug) {
Serial.print("Config version=");
Serial.println(bTmp);
}
if (bTmp!=255) {
EEPROM.get(sizeof(bTmp),ldrDark);
EEPROM.get(sizeof(bTmp)+sizeof(ldrDark),pwm1Low);
EEPROM.get(sizeof(bTmp)+sizeof(ldrDark)+sizeof(pwm1Low),pwm1High);
EEPROM.get(sizeof(bTmp)+sizeof(ldrDark)+sizeof(pwm1Low)+sizeof(pwm1High),pwm2Low);
EEPROM.get(sizeof(bTmp)+sizeof(ldrDark)+sizeof(pwm1Low)+sizeof(pwm1High)+sizeof(pwm2Low),pwm2High);
EEPROM.get(sizeof(bTmp)+sizeof(ldrDark)+sizeof(pwm1Low)+sizeof(pwm1High)+sizeof(pwm2Low)+sizeof(pwm2High),pwm3Low);
EEPROM.get(sizeof(bTmp)+sizeof(ldrDark)+sizeof(pwm1Low)+sizeof(pwm1High)+sizeof(pwm2Low)+sizeof(pwm2High)+sizeof(pwm3Low),pwm3High);
EEPROM.get(sizeof(bTmp)+sizeof(ldrDark)+sizeof(pwm1Low)+sizeof(pwm1High)+sizeof(pwm2Low)+sizeof(pwm2High)+sizeof(pwm3Low)+sizeof(pwm3High),loopDelay);
if (loopDelay>50) {
loopDelay=50;
}
if (loopDelay<0) {
loopDelay=0;
}
}
}
void writeConfig() {
EEPROM.put(0,(byte)1);
EEPROM.put(sizeof(byte),ldrDark);
EEPROM.put(sizeof(byte)+sizeof(ldrDark),pwm1Low);
EEPROM.put(sizeof(byte)+sizeof(ldrDark)+sizeof(pwm1Low),pwm1High);
EEPROM.put(sizeof(byte)+sizeof(ldrDark)+sizeof(pwm1Low)+sizeof(pwm1High),pwm2Low);
EEPROM.put(sizeof(byte)+sizeof(ldrDark)+sizeof(pwm1Low)+sizeof(pwm1High)+sizeof(pwm2Low),pwm2High);
EEPROM.put(sizeof(byte)+sizeof(ldrDark)+sizeof(pwm1Low)+sizeof(pwm1High)+sizeof(pwm2Low)+sizeof(pwm2High),pwm3Low);
EEPROM.put(sizeof(byte)+sizeof(ldrDark)+sizeof(pwm1Low)+sizeof(pwm1High)+sizeof(pwm2Low)+sizeof(pwm2High)+sizeof(pwm3Low),pwm3High);
EEPROM.put(sizeof(byte)+sizeof(ldrDark)+sizeof(pwm1Low)+sizeof(pwm1High)+sizeof(pwm2Low)+sizeof(pwm2High)+sizeof(pwm3Low)+sizeof(pwm3High),loopDelay);
}
void printConfig() {
Serial.print("loopDelay=");
Serial.println(loopDelay);
Serial.print("pwm1Low=");
Serial.println(pwm1Low);
Serial.print("pwm1High=");
Serial.println(pwm1High);
Serial.print("pwm2Low=");
Serial.println(pwm2Low);
Serial.print("pwm2High=");
Serial.println(pwm2High);
Serial.print("pwm3Low=");
Serial.println(pwm3Low);
Serial.print("pwm3High=");
Serial.println(pwm3High);
Serial.print("ldrDark=");
Serial.println(ldrDark);
}
void set() {
//SET LDRDARK x
if (inputString.length()>=11 && inputString.startsWith(SET_LDRDARK)) {
//Check that there is a parameter after command.
if (inputString.length()>12) {
iTmp=inputString.substring(12).toInt();
if (iTmp>=0 && iTmp<=1023) {
ldrDark=iTmp;
Serial.print("LDRDARK set to ");
Serial.println(ldrDark);
} else {
Serial.println("LDRDARK must be between 0 - 1023.");
}
} else {
Serial.println("SET LDRDARK must have a parameter between 0 - 1023.");
}
//SET PWM1LOW x
} else if (inputString.length()>=11 && inputString.startsWith(SET_PWM1LOW)) {
//Check that there is a parameter after command.
if (inputString.length()>12) {
iTmp=inputString.substring(12).toInt();
if (iTmp>=0 && iTmp<=255) {
pwm1Low=iTmp;
Serial.print("PWM1LOW set to ");
Serial.println(pwm1Low);
} else {
Serial.println("PWM1LOW must be between 0 - 255.");
}
} else {
Serial.println("SET PWM1LOW must have a parameter between 0 - 255.");
}
//SET PWM2LOW x
} else if (inputString.length()>=11 && inputString.startsWith(SET_PWM2LOW)) {
//Check that there is a parameter after command.
if (inputString.length()>12) {
iTmp=inputString.substring(12).toInt();
if (iTmp>=0 && iTmp<=255) {
pwm2Low=iTmp;
Serial.print("PWM2LOW set to ");
Serial.println(pwm2Low);
} else {
Serial.println("PWM2LOW must be between 0 - 255.");
}
} else {
Serial.println("SET PWM2LOW must have a parameter between 0 - 255.");
}
//SET PWM3LOW x
} else if (inputString.length()>=11 && inputString.startsWith(SET_PWM3LOW)) {
//Check that there is a parameter after command.
if (inputString.length()>12) {
iTmp=inputString.substring(12).toInt();
if (iTmp>=0 && iTmp<=255) {
pwm3Low=iTmp;
Serial.print("PWM3LOW set to ");
Serial.println(pwm3Low);
} else {
Serial.println("PWM3LOW must be between 0 - 255.");
}
} else {
Serial.println("SET PWM3LOW must have a parameter between 0 - 255.");
}
//SET PWM1HIGH x
} else if (inputString.length()>=12 && inputString.startsWith(SET_PWM1HIGH)) {
//Check that there is a parameter after command.
if (inputString.length()>13) {
iTmp=inputString.substring(13).toInt();
if (iTmp>=0 && iTmp<=255) {
pwm2Low=iTmp;
Serial.print("PWM1HIGH set to ");
Serial.println(pwm1High);
} else {
Serial.println("PWM1HIGH must be between 0 - 255.");
}
} else {
Serial.println("SET PWM1HIGH must have a parameter between 0 - 255.");
}
//SET PWM2HIGH x
} else if (inputString.length()>=12 && inputString.startsWith(SET_PWM2HIGH)) {
//Check that there is a parameter after command.
if (inputString.length()>13) {
iTmp=inputString.substring(13).toInt();
if (iTmp>=0 && iTmp<=255) {
pwm2Low=iTmp;
Serial.print("PWM2HIGH set to ");
Serial.println(pwm2High);
} else {
Serial.println("PWM2HIGH must be between 0 - 255.");
}
} else {
Serial.println("SET PWM2HIGH must have a parameter between 0 - 255.");
}
//SET PWM3HIGH x
} else if (inputString.length()>=12 && inputString.startsWith(SET_PWM3HIGH)) {
//Check that there is a parameter after command.
if (inputString.length()>13) {
iTmp=inputString.substring(13).toInt();
if (iTmp>=0 && iTmp<=255) {
pwm3Low=iTmp;
Serial.print("PWM3HIGH set to ");
Serial.println(pwm3High);
} else {
Serial.println("PWM3HIGH must be between 0 - 255.");
}
} else {
Serial.println("SET PWM3HIGH must have a parameter between 0 - 255.");
}
//SET LOOPDELAY x
} else if (inputString.length()>=13 && inputString.startsWith(SET_LOOPDELAY)) {
//Check that there is a parameter after command.
if (inputString.length()>13) {
iTmp=inputString.substring(13).toInt();
if (iTmp>=0 && iTmp<=255) {
loopDelay=iTmp;
Serial.print("LOOPDELAY set to ");
Serial.println(loopDelay);
} else {
Serial.println("LOOPDELAY must be between 0 - 255.");
}
} else {
Serial.println("SET PWM2HIGH must have a parameter between 0 - 255.");
}
} else {
Serial.println("Unkown command after SET, must be LDRDARK, PWM1HIGH, PWM2HIGH, PWM1LOW, PWM2LOW.");
}
}
/*
SerialEvent occurs whenever a new data comes in the
hardware serial RX. This routine is run between each
time loop() runs, so using delay inside loop can delay
response. Multiple bytes of data may be available.
*/
void serialEvent() {
while (Serial.available()) {
// get the new byte:
char inChar = (char)Serial.read();
// if the incoming character is a newline, set a flag
// so the main loop can do something about it:
if (inChar == '\n') {
stringComplete = true;
} else {
// add it to the inputString:
inputString += inChar;
}
}
}
| 30.181319
| 154
| 0.657655
|
8bc2c236951bb633a48af3cc49473aac4fabfe1c
| 244
|
ino
|
Arduino
|
firmware/lm-matrix/x99_main.ino
|
sergiosergito/matrix
|
a6866b61b4971c93173225fe880e1b060011e25d
|
[
"MIT"
] | 1
|
2017-02-21T08:15:54.000Z
|
2017-02-21T08:15:54.000Z
|
firmware/lm-matrix/x99_main.ino
|
sergiosergito/matrix
|
a6866b61b4971c93173225fe880e1b060011e25d
|
[
"MIT"
] | null | null | null |
firmware/lm-matrix/x99_main.ino
|
sergiosergito/matrix
|
a6866b61b4971c93173225fe880e1b060011e25d
|
[
"MIT"
] | null | null | null |
void setup() {
commSetup();
buttonSetup();
displaySetup();
imagesSetup();
animationSetup();
textSetup();
modeSetup();
eepromSetup();
Serial.println("+ready");
}
void loop() {
commCheck();
buttonCheck();
modeLoop();
}
| 12.2
| 27
| 0.610656
|
c502477aa84fe05b8701eec21942da5a5e3fcf9a
| 7,122
|
ino
|
Arduino
|
TCC_PED/TCC_PED/TCC_PED.ino
|
faccuser/adevecchi2015s1
|
86fe46f8fbb1367eaf95fcdfdecdcc5808fa0db7
|
[
"MIT"
] | null | null | null |
TCC_PED/TCC_PED/TCC_PED.ino
|
faccuser/adevecchi2015s1
|
86fe46f8fbb1367eaf95fcdfdecdcc5808fa0db7
|
[
"MIT"
] | null | null | null |
TCC_PED/TCC_PED/TCC_PED.ino
|
faccuser/adevecchi2015s1
|
86fe46f8fbb1367eaf95fcdfdecdcc5808fa0db7
|
[
"MIT"
] | null | null | null |
/*
* Projeto:
* - Ponto Eletrônico Digital
*
* Descrição:
* - TCC para a Faccamp Facundade Campo Limpo Paulista,
* como requesito parcial para obtenção do título de
* Bacharel em Ciência da Computação.
*
* - Este projeto é um Ponto Eletrônico Digital com interface
* ethernet para persistir os registros de data e hora a uma
* base de dados em um servidor Web
*
* Circuito:
* - Ethernet shield utiliza os pinos 10, 11, 12, 13
*
* - RFID-RC522 breakout utiliza os pinos 8, 9, 11, 12, 13
*
* - RTC DS1307 breakout utiliza os pinos AN4 e AN5
*
* - LCD 16x2 utiliza os pinos 2, 3, 4, 5, 6, 7
*
* criado em 26 Abril 2015
* by Andre Devecchi
* contato: andre.devecchi@gmail.com
* ----------------------------------------------------------------------------
* The MIT License (MIT)
*
* Copyright (c) 2014 Devecchi, André; Silva, André; faccuser@gmail.com
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <SPI.h>
#include <DS1307.h>
#include <MFRC522.h>
#include <Ethernet.h>
#include <ArduinoJson.h>
#include <LiquidCrystal.h>
char* requestServer();
const char* parseJson();
byte status;
char* jsonString;
// Inicializa RTC
DS1307 rtc(A4, A5);
// Inicializa MFRC522
#define SS_PIN 9
#define RST_PIN 8
MFRC522 mfrc522(SS_PIN, RST_PIN);
// Endereço MAC do Ethernet Shield
byte mac[] = {
0x90, 0xA2, 0xDA, 0x0F, 0x3A, 0xDC };
// Endereço IP do Servidor
IPAddress server( 192, 168, 1, 100 ); //server( 192, 168, 1, 105 );
// Endereço IP do Arduino
IPAddress ip( 192, 168, 1, 110 );
// Inicializa o Ethernet client library
// com o endereço IP do servidor (porta 80 é padrão para HTTP)
EthernetClient client;
// Inicializa LCD
LiquidCrystal lcd(7, 6, 5, 4, 3, 2);
void setup() {
SPI.begin(); // Inicia SPI bus
mfrc522.PCD_Init(); // Inicia MFRC522
rtc.halt(false); //Aciona o relogio
lcd.begin(16, 2); //Define o LCD com 16 colunas e 2 linhas
//As linhas abaixo setam a data e hora do modulo
//e podem ser comentada apos a primeira utilizacao
//rtc.setDOW(THURSDAY); //Define o dia da semana
//rtc.setTime(18, 22, 00); //Define o horario
//rtc.setDate(14, 5, 2015); //Define o dia, mes e ano
//Definicoes do pino SQW/Out
rtc.setSQWRate(SQW_RATE_1);
rtc.enableSQW(true);
Serial.begin(9600);
// inicia a conexão Ethernet
if (Ethernet.begin(mac) == 0) {
Serial.println("Falha para configurar Ethernet usando DHCP");
Ethernet.begin(mac, ip);
}
// da ao Ethernet shield um segundo para inicializar
delay(1000);
Serial.println("Conectando...");
}
void loop()
{
// Look for new cards
if ( ! mfrc522.PICC_IsNewCardPresent())
{
//return;
status = 0;
}
// Select one of the cards
if ( ! mfrc522.PICC_ReadCardSerial())
{
//return;
status = 0;
}
else
{
status = 1;
}
switch (status)
{
case 0:
//Mostra a hora atual no display
lcd.setCursor(4, 0);
lcd.print(rtc.getTimeStr());
//Mostra a data atual no display
lcd.setCursor(1, 1);
lcd.print(rtc.getDateStr(FORMAT_LONG, FORMAT_LITTLEENDIAN, '/'));
//Mostra o dia da semana no display
lcd.setCursor(12, 1);
lcd.print(rtc.getDOWStr(FORMAT_SHORT));
//Aguarda 1 segundo e repete o processo
delay (1000);
break;
case 1:
String conteudo= "";
for (byte i = 0; i < mfrc522.uid.size; i++)
{
conteudo.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " "));
conteudo.concat(String(mfrc522.uid.uidByte[i], HEX));
}
conteudo.toUpperCase();
conteudo.trim();
jsonString = requestServer(conteudo);
const char* nome = parseJson();
Serial.println();
Serial.println(nome);
lcd.clear();
lcd.setCursor(1,0);
lcd.print(nome);
Time t = rtc.getTime();
if (t.hour < 12)
{
lcd.setCursor(4,1);
lcd.print("Bom Dia!");
}
else if (t.hour < 18)
{
lcd.setCursor(3,1);
lcd.print("Boa Tarde!");
}
else
{
lcd.setCursor(3,1);
lcd.print("Boa Noite!");
}
delay(3000);
lcd.clear();
break;
}
}
char* requestServer(String uid)
{
boolean readJson = false;
byte i = 0;
char* output = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
String data;
data = "uid="+uid+"&hora="+rtc.getTimeStr()+"&data="+rtc.getDateStr(FORMAT_LONG, FORMAT_LITTLEENDIAN, '/')+"&dia="+rtc.getDOWStr(FORMAT_SHORT);
// inicia conexão com servidor
if (client.connect(server, 80)) {
Serial.println("Conectado");
client.println("POST /tcc/ponto-eletronico.php HTTP/1.1");
client.println("Host: 192.168.1.100");
client.println("User-Agent: Arduino/1.0");
client.println("Connection: close");
client.println("Content-Type: application/x-www-form-urlencoded;");
client.print("Content-Length: ");
client.println(data.length());
client.println();
client.println(data);
client.println();
//Aguardando conexao
while(!client.available()){
delay(1);
}
// Percorre os caracteres do envelope HTTP do servidor e armazena na String apenas o conteudo JSON
while ( client.available() ) {
char c = client.read();
if ( c == '{' ) {
readJson = true;
}
if ( readJson ) {
output[i++] = c;
if ( c == '}' ) {
output[i] = '0';
}
}
}
}
else {
// não hove conexão com o servidor
Serial.println("Conexão Falhou");
}
//Aguarda a desconexao com o servidor
while( client.connected() ) {
delay(1);
}
// desconectado o cliente
if (!client.connected()) {
Serial.println();
Serial.println("Desconectado.");
client.stop();
}
return output;
}
const char* parseJson()
{
StaticJsonBuffer<29> jsonBuffer;
JsonObject& root = jsonBuffer.parseObject(jsonString);
if (!root.success()) {
return "parseObject() failed";
}
return root["nome"];
}
| 25.526882
| 145
| 0.621595
|
af8af9c07bd437906703c3806c9a7fccaacba2aa
| 294
|
ino
|
Arduino
|
Display_test/Display_test.ino
|
ScheerleJo/Macro_Keyboard
|
4f75954029f05c68275e411cb945c86da88d9960
|
[
"MIT"
] | null | null | null |
Display_test/Display_test.ino
|
ScheerleJo/Macro_Keyboard
|
4f75954029f05c68275e411cb945c86da88d9960
|
[
"MIT"
] | 1
|
2022-03-18T23:14:37.000Z
|
2022-03-18T23:14:37.000Z
|
Display_test/Display_test.ino
|
ScheerleJo/Macro_Keyboard
|
4f75954029f05c68275e411cb945c86da88d9960
|
[
"MIT"
] | null | null | null |
#include <SPI.h>
#include "LCD_Driver.h"
#include "GUI_Paint.h"
#include "image.h"
void setup() {
DIN = pinMode(10, OUTPUT);
CLK = pinMode(8, OUTPUT);
CS = pinMode(9, OUTPUT);
DC = pinMode(11, OUTPUT);
RST = pinMode(12, OUTPUT);
BL = pinMode(13, OUTPUT);
}
void loop() {
}
| 13.363636
| 28
| 0.608844
|
41b5675d07574fad2f214eb3702d2b336e69191d
| 2,261
|
ino
|
Arduino
|
tinkering/motor/motor_unit_test_3/motor_unit_test_3.ino
|
fkmclane/derailleurs
|
087dfab4d5894a868517364d6ba19f2662dc7731
|
[
"MIT"
] | null | null | null |
tinkering/motor/motor_unit_test_3/motor_unit_test_3.ino
|
fkmclane/derailleurs
|
087dfab4d5894a868517364d6ba19f2662dc7731
|
[
"MIT"
] | null | null | null |
tinkering/motor/motor_unit_test_3/motor_unit_test_3.ino
|
fkmclane/derailleurs
|
087dfab4d5894a868517364d6ba19f2662dc7731
|
[
"MIT"
] | 1
|
2020-02-23T19:11:58.000Z
|
2020-02-23T19:11:58.000Z
|
/*
This is an integrated test to automate the shifting. It is similar
to unit test 2, but instead of being activated by manually pushing
a button, it receives signals to shift from the sensor module.
The button inputs are replaced by two spare input pins that connect
to the other microcontroller running hall_decision_test.
*/
// include built in stepper library
#include <Stepper.h>
// define signal pins
#define P1 P1_3
#define P2 P1_4
// define enable pins
#define enable_1 18
#define enable_2 19
// specify how many steps the motor has for one revolution
const int stepsPerRevolution = 200;
// initalize the motor
Stepper myStepper(stepsPerRevolution, 12,13,5,9);
// set steps per shift
int shift = 500;
// set variables
short up;
short down;
// initalize count
int gear = 1;
// function prototypes
void enable();
void disable();
void shift_up();
void shift_down();
void setup() {
// set the speed at 60 rpm:
myStepper.setSpeed(60);
// initialize the serial port:
Serial.begin(9600);
// Enable pin pull-up for the buttons
pinMode(P4_5, INPUT_PULLUP);
pinMode(P1_1, INPUT_PULLUP);
// set modes for enable pins
pinMode(enable_1, OUTPUT);
pinMode(enable_2, OUTPUT);
}
void loop() {
// Read button pins
up = digitalRead(P1);
down = digitalRead(P2);
// // Enable or disable motor
// if (up == 0 || down == 0) {
// enable();
// }
// else {
// disable();
// }
// Turn motor if a button is pressed
if (up == 0) {
if (gear < 7) {
enable();
shift_up();
disable();
gear ++;
}
Serial.print("Gear: ");
Serial.println(gear);
}
if (down == 0) {
if (gear > 1) {
enable();
shift_down();
disable();
gear --;
}
Serial.print("Gear: ");
Serial.println(gear);
}
}
// supporting functions
void enable() {
Serial.println("Enabled");
digitalWrite(enable_1, HIGH);
digitalWrite(enable_2, HIGH);
}
void disable() {
Serial.println("Disabled");
digitalWrite(enable_1, LOW);
digitalWrite(enable_2, LOW);
}
void shift_up() {
myStepper.step(shift);
Serial.print("Shifted ");
Serial.println(shift);
}
void shift_down() {
myStepper.step(-shift);
Serial.print("Shifted ");
Serial.println(-shift);
}
| 17.80315
| 67
| 0.649713
|
ad63770a91b35d5413dfb9d7526eab63dfa5d0f6
| 1,069
|
ino
|
Arduino
|
mechanics/motorcontrol/BLDC/bldc_ctrl.ino
|
real-lake050317/Wheelchairproject
|
84e94b79f3d4d72b825755d4e4941558f6342b4b
|
[
"BSD-2-Clause"
] | 2
|
2022-02-05T14:55:09.000Z
|
2022-03-29T10:21:21.000Z
|
mechanics/motorcontrol/BLDC/bldc_ctrl.ino
|
real-lake050317/Wheelchairproject
|
84e94b79f3d4d72b825755d4e4941558f6342b4b
|
[
"BSD-2-Clause"
] | 4
|
2021-11-23T16:48:18.000Z
|
2022-03-20T23:23:18.000Z
|
mechanics/motorcontrol/BLDC/bldc_ctrl.ino
|
real-lake050317/Wheelchairproject
|
84e94b79f3d4d72b825755d4e4941558f6342b4b
|
[
"BSD-2-Clause"
] | 1
|
2022-03-18T07:31:52.000Z
|
2022-03-18T07:31:52.000Z
|
#include <Servo.h>
Servo motor1, motor2; //motor1: 왼쪽 모터, motor2: 오른쪽 모터
// 왼쪽모터는 정방향 회전이 전진
// 오른쪽 모터는 역방향 회전이 전진 -> + - 극을 반대로 연결해 방향을 반대로 제어할 수 있음
int speed1 = 0, speed2 = 0;
int pos1 = 0, pos2 = 0;
char receivedChar;
boolean newData = false;
void setup(){
Serial.begin(9600);
motor1.attach(10);
motor2.attach(9);
}
void recvOneChar() {
newData = false;
if (Serial.available() > 0) {
receivedChar = Serial.read();
newData = true;
}
}
/*\pos var이 63일때 돌기 시작함\*/
void runMotor1() {
motor1.write(65);
}
void stopMotor1() {
motor1.write(0);
}
void runMotor2() {
motor2.write(65);
}
void stopMotor2() {
motor2.write(0);
}
void goStraight() {
runMotor1();
runMotor2();
}
void goBackward() { //ESC Motors
}
void
void loop(){
receivedChar = 'a';
recvOneChar();
if (newData) {
if (receivedChar == 's'){
}
else if (receivedChar == 'b'){
}
else if (receivedChar == 'l'){
}
else if (receivedChar == 'r'){
}
}
}
| 13.883117
| 56
| 0.546305
|
e3dfb247e9d57a70c204f2983d0aec84d733a953
| 7,810
|
ino
|
Arduino
|
arduino/chaser_new/chaser_new.ino
|
Utsav22G/CrabBots
|
72d08ea708d190ac2b437694fe5020293e668e71
|
[
"MIT"
] | null | null | null |
arduino/chaser_new/chaser_new.ino
|
Utsav22G/CrabBots
|
72d08ea708d190ac2b437694fe5020293e668e71
|
[
"MIT"
] | null | null | null |
arduino/chaser_new/chaser_new.ino
|
Utsav22G/CrabBots
|
72d08ea708d190ac2b437694fe5020293e668e71
|
[
"MIT"
] | null | null | null |
#include <Adafruit_NeoPixel.h>
#include <Wire.h>
#include <Adafruit_LIS3DH.h>
#include <Adafruit_Sensor.h>
#include "WS2812_Definitions.h"
// -----------------------
// DEFINE PINS
// -----------------------
#define RED1 A2 // input for red photodiode
#define RED2 A3 // input for blue photodiode
#define BPWM 10
#define APWM 9
#define BDIR 5
#define ADIR 4
#define MUX0 2
#define MUX1 3
#define LED_COUNT 20
#define LED_INPUT 7
// ---------------------
// DEFINE VARIABLES TO
// READ SENSORS
// ---------------------
// front = 0, right = 1, left = 2, back = 3
int init_red_one; // ambient reference value
int init_red_two;
int init_red_three;
int init_red_four;
int init_red_five;
int init_red_six;
int init_red_seven;
int init_red_eight;
int curr_red_one; // current value
int curr_red_two;
int curr_red_three;
int curr_red_four;
int curr_red_five;
int curr_red_six;
int curr_red_seven;
int curr_red_eight;
int left2red;
int right2red;
int left2blue;
int right2blue;
int left3red;
int right3red;
int left3blue;
int right3blue;
int red_front;
int red_right;
int red_back;
int red_left;
int mux_delay = 5;
int motor_delay = 5;
unsigned long prevTime = 0;
unsigned long currTime;
int programCounter = 0;
bool bump = false;
// ---------------------
// DEFINE VARIABLES TO
// SEND MOTOR COMMANDS
// ---------------------
float left1; // left motor commands to be summed
float left2;
float left3;
float left4;
float right1; // right motor commands to be summed
float right2;
float right3;
float right4;
float left_total = 0;
float right_total = 0;
float sens = 2;
float scale = 1;
int bluesum;
// ---------------------
// DEFINE VARIABLES FOR
// LED STRIP
// ---------------------
int brightness = 64;
int R = 20;
int G = 0;
int B = 0;
Adafruit_NeoPixel strip = Adafruit_NeoPixel(LED_COUNT, LED_INPUT, NEO_RGB + NEO_KHZ800);
Adafruit_LIS3DH lis = Adafruit_LIS3DH();
void setup() {
delay(5000);
Serial.begin(9600);
pinMode(RED1,INPUT);
pinMode(RED2,INPUT);
pinMode(APWM,OUTPUT);
pinMode(ADIR,OUTPUT);
pinMode(BPWM,OUTPUT);
pinMode(BDIR,OUTPUT);
pinMode(MUX0, OUTPUT);
pinMode(MUX1, OUTPUT);
pinMode(LED_INPUT, OUTPUT);
digitalWrite(MUX0, LOW); // set mux select to 0
digitalWrite(MUX1, HIGH);
delay(150);
init_red_one = analogRead(RED2); // take initial front values to calibrate
digitalWrite(MUX0, LOW); // set mux select to 0
digitalWrite(MUX1, LOW);
delay(150);
init_red_two = analogRead(RED2);
digitalWrite(MUX0, HIGH); // set mux select to 0
digitalWrite(MUX1, HIGH);
delay(150);
init_red_three = analogRead(RED1); // take initial front values to calibrate
digitalWrite(MUX0, HIGH); // set mux select to 0
digitalWrite(MUX1, LOW);
delay(150);
init_red_four = analogRead(RED1);
digitalWrite(MUX0, LOW); // set mux select to 0
digitalWrite(MUX1, HIGH);
delay(150);
init_red_five = analogRead(RED1); // take initial front values to calibrate
digitalWrite(MUX0, LOW); // set mux select to 0
digitalWrite(MUX1, LOW);
delay(150);
init_red_six = analogRead(RED1);
digitalWrite(MUX0, HIGH); // set mux select to 0
digitalWrite(MUX1, HIGH);
delay(150);
init_red_seven = analogRead(RED2); // take initial front values to calibrate
digitalWrite(MUX0, HIGH); // set mux select to 0
digitalWrite(MUX1, LOW);
init_red_two = analogRead(RED2);
if (! lis.begin(0x18)) { // change this to 0x19 for alternative i2c address
while (1){
digitalWrite(8,HIGH);
delay(250);
digitalWrite(8,LOW);
delay(250);
}
}
lis.setRange(LIS3DH_RANGE_16_G); // 2, 4, 8 or 16 G!
strip.begin();
colorWipe(strip.Color(0, 0, 0)); // Off
strip.show();
}
void loop() {
currTime = millis();
//ReadPhotodiodes();
lis.read(); // get X Y and Z data at once
sensors_event_t event;
lis.getEvent(&event);
if(abs(event.acceleration.z) > 20) {
if (bump){
bump = false;
}
else{
bump = true;
}
}
if(bump) {
colorWipe(strip.Color(0, 0, 0)); // Off
delay(500);
colorWipe(strip.Color(0, 0, 255));
bump = false;
} else {
colorWipe(strip.Color(0, 0, 255)); // Red
ReadPhotodiodes();
Move();
}
//Move();
}
int ReadPhotodiodes() {
// ---------------------------
// find current values of red
// and blue by subtracting from
// ambient value
//
// take reading from front
// r -> +L +R
// b -> 0
// scale values based on brightness
// ----------------------------
digitalWrite(MUX0, LOW); // set mux select to 0
digitalWrite(MUX1, HIGH);
delay(mux_delay);
curr_red_one = analogRead(RED2); // take initial front values to calibrate
digitalWrite(MUX0, LOW); // set mux select to 0
digitalWrite(MUX1, LOW);
delay(mux_delay);
curr_red_two = analogRead(RED2);
//red_front = (2*((curr_red_one-init_red_one)+(curr_red_two-init_red_two)))/2;
red_front = curr_red_one - init_red_one;
if(red_front >= 10) {
left1 = 100;
right1 = 100;
} else {
left1 = 0;
right1 = 0;
}
// ---------------------------
// take reading from right
// r -> +L -R
// b -> -L +R
// ----------------------------
digitalWrite(MUX0, HIGH); // set mux select to 0
digitalWrite(MUX1, HIGH);
delay(mux_delay);
curr_red_three = analogRead(RED1); // take initial front values to calibrate
digitalWrite(MUX0, HIGH); // set mux select to 0
digitalWrite(MUX1, LOW);
delay(mux_delay);
curr_red_four = analogRead(RED1);
red_right = (2*((curr_red_three-init_red_three)+(curr_red_four-init_red_four)))/2;
//red_right = curr_red_three-init_red_three;
if(red_right >= 5) {
left2red = 50 + (sens*red_right);
right2red = 50 + (sens*red_right);
} else {
left2red = 0;
right2red = 0;
}
left2 = left2red;
right2 = -right2red;
// ---------------------------
// take reading from left
// r -> -L +R
// b -> +L -R
// ----------------------------
digitalWrite(MUX0, HIGH); // set mux select to 0
digitalWrite(MUX1, HIGH);
delay(mux_delay);
curr_red_seven = analogRead(RED2); // take initial front values to calibrate
digitalWrite(MUX0, HIGH); // set mux select to 0
digitalWrite(MUX1, LOW);
delay(mux_delay);
curr_red_eight = analogRead(RED2);
red_left = (2*((curr_red_seven-init_red_seven)+(curr_red_eight-init_red_eight)))/2;
//red_left = curr_red_seven-init_red_seven;
if(red_left >= 5) {
left3red = 50 + (sens*red_left);
right3red = 50 + (sens*red_left);
} else {
left3red = 0;
right3red = 0;
}
left3 = -left3red;
right3 = right3red;
// ---------------------------
// take reading from back
// r -> 0
// b -> +L +R
// ----------------------------
digitalWrite(MUX0, LOW); // set mux select to 0
digitalWrite(MUX1, HIGH);
delay(mux_delay);
curr_red_five = analogRead(RED1); // take initial front values to calibrate
digitalWrite(MUX0, LOW); // set mux select to 0
digitalWrite(MUX1, LOW);
delay(mux_delay);
curr_red_six = analogRead(RED1);
red_back = (2*((curr_red_five-init_red_five)+(curr_red_six-init_red_six)))/2;
}
int Move() {
// ----------------------------
// Sum all motor response and
// send response to the motors
// ----------------------------
left_total = scale*(left1 + left2 + left3 + left4) - 40;
right_total = scale*(right1 + right2 + right3 + right4) - 40;
digitalWrite(ADIR,HIGH);
digitalWrite(BDIR,LOW);
/*if(diff_red_front >= 80) {
left_total = 0;
right_total = 0;
}*/
if(left_total <= 0) {
left_total = 0;
}
if(right_total <= 0) {
right_total = 0;
}
analogWrite(APWM,left_total);
analogWrite(BPWM,right_total);
delay(motor_delay);
}
void colorWipe(uint32_t c) {
for(uint16_t i=0; i<strip.numPixels(); i++) {
strip.setPixelColor(i, c);
strip.show();
}
}
| 22.124646
| 88
| 0.624968
|
d496003345e35524bd0cfef3612a39de19670948
| 2,214
|
ino
|
Arduino
|
combinedCodeUno/combinedCodeUno.ino
|
richiebful/arduinoTag
|
ed2b6ec1eeb72b07af5c62b52db567ff5238d933
|
[
"MIT"
] | 3
|
2015-12-14T07:22:53.000Z
|
2019-08-01T14:38:00.000Z
|
combinedCodeUno/combinedCodeUno.ino
|
richiebful/arduinoTag
|
ed2b6ec1eeb72b07af5c62b52db567ff5238d933
|
[
"MIT"
] | null | null | null |
combinedCodeUno/combinedCodeUno.ino
|
richiebful/arduinoTag
|
ed2b6ec1eeb72b07af5c62b52db567ff5238d933
|
[
"MIT"
] | null | null | null |
unsigned long previousMillis;
unsigned long blinkInterval = 500;
int reloadButtonPin = 53;
int fireButtonPin = 52;
int firePin = 51;
int ammo_vPin = 50;
int laser = 49;
int ledPins[4] = {23,24,25,26};
int sensorPin = 22;
int life_v = 4;
int clip_v = 6;
int last_life_v = 4;
int last_clip_v = 6;
const int clip_max = 6;
void
setup()
{
Serial.begin(9600);
pinMode(sensorPin, INPUT);
pinMode(reloadButtonPin, INPUT);
pinMode(fireButtonPin, INPUT);
pinMode(laser, OUTPUT);
pinMode(firePin, OUTPUT);
pinMode(ammo_vPin, OUTPUT);
for (int i = 0; i < 4; i++){
pinMode(ledPins[i], OUTPUT);
}
}
void loop(){
dispAmmo();
dispLife();
unsigned int total = 0;
long datum;
datum = pulseIn(sensorPin, LOW, 1000);
if (life_v <= 0){
delay(3000);
life_v = 4;
}
if (datum > 100) {
Serial.println("Shot");
life_v--;
delay(500);
}
if (digitalRead(fireButtonPin)== HIGH && clip_v > 0){
Serial.println("Pushed in");
while (digitalRead(fireButtonPin) == HIGH){}
Serial.println("Fire Button");
digitalWrite(firePin, LOW);
digitalWrite(laser, HIGH);
delay(100);
digitalWrite(firePin, HIGH);
digitalWrite(laser, LOW);
clip_v--;
}
Serial.println("Ammo");
Serial.println(clip_v);
Serial.println("Health");
Serial.println(life_v);
if (digitalRead(reloadButtonPin) == HIGH){
while (digitalRead(reloadButtonPin) == HIGH){}
clip_v = clip_max;
}
}
void dispAmmo(){
if (clip_v <= 0){
digitalWrite(ammo_vPin, HIGH);
}
else{
digitalWrite(ammo_vPin, LOW);
}
}
void dispLife(){
Serial.println(life_v);
for (int i = 0; i < life_v; i++){
digitalWrite(ledPins[i], HIGH);
}
for (int j = life_v; j < 4; j++){
digitalWrite(ledPins[j], LOW);
}
}
/*
* void blinkLed(){ unsigned long currentMillis = millis();
* if(currentMillis - previousMillis > blinkInterval) { // save the last
* time you blinked the LED previousMillis = currentMillis; // if the LED
* is off turn it on and vice-versa: if (ledState == LOW){ ledState =
* HIGH; }else{ ledState = LOW; } // set the LED with the ledState of the
* variable: digitalWrite(ledPin, ledState); } }
*/
| 22.14
| 73
| 0.629178
|
95bab3cf565d4e9c7c35f92db5932bd968b26250
| 201
|
ino
|
Arduino
|
DC_motors/motor_pot/motor_pot.ino
|
gren236/study_arduino
|
68c3ca415f6c90e2adad75be36219d78114eea20
|
[
"MIT"
] | null | null | null |
DC_motors/motor_pot/motor_pot.ino
|
gren236/study_arduino
|
68c3ca415f6c90e2adad75be36219d78114eea20
|
[
"MIT"
] | null | null | null |
DC_motors/motor_pot/motor_pot.ino
|
gren236/study_arduino
|
68c3ca415f6c90e2adad75be36219d78114eea20
|
[
"MIT"
] | null | null | null |
const int MOTOR = 9;
const int POT = 0;
int val = 0;
void setup() {
pinMode(MOTOR, OUTPUT);
}
void loop() {
val = analogRead(POT);
val = map(val, 0, 1023, 0, 255);
analogWrite(MOTOR, val);
}
| 14.357143
| 34
| 0.60199
|
45f00faa0e8c52990ebc34a594c58ce3ca263a19
| 5,824
|
ino
|
Arduino
|
ino/client/client.ino
|
HarvardURC/MATE_ROV
|
30f7dc3a1caa6532e5cd44e3029de5353e79d656
|
[
"MIT"
] | 1
|
2018-04-09T00:57:10.000Z
|
2018-04-09T00:57:10.000Z
|
ino/client/client.ino
|
HarvardURC/MATE_ROV
|
30f7dc3a1caa6532e5cd44e3029de5353e79d656
|
[
"MIT"
] | 27
|
2017-10-03T02:02:32.000Z
|
2018-04-09T19:44:41.000Z
|
ino/client/client.ino
|
HarvardURC/MATE_ROV
|
30f7dc3a1caa6532e5cd44e3029de5353e79d656
|
[
"MIT"
] | 1
|
2017-10-27T01:39:31.000Z
|
2017-10-27T01:39:31.000Z
|
#include <Wire.h>
#include <Servo.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BNO055.h>
#include <utility/imumaths.h>
#define TICKS_PER_WRITE 200
#define PANSERVO 2
#define TILTSERVO 3
#define T1 4
#define T2 5
#define T3 6
#define T4 7
#define T5 8
#define T6 9
#define FRONT_LEFT 0
#define FRONT_RIGHT 1
#define BACK_LEFT 2
#define BACK_RIGHT 3
#define LEFT_MIDDLE 4
#define RIGHT_MIDDLE 5
#define THRUSTER_BASE 1500
#define THRUSTER_MAX 400
struct message {
float x;
float y;
float z;
float roll;
float pitch;
float yaw;
float cameraTilt;
float cameraPan;
};
Adafruit_BNO055 bno = Adafruit_BNO055(55);
int ticks = 0;
Servo panServo;
Servo tiltServo;
Servo thrusters[6];
int panPos = 90;
int tiltPos = 90;
struct message curMsg;
void setup(void)
{
Serial.begin(9600);
// Initialise the IMU
if(!bno.begin()) {
Serial.print("Ooops, no BNO055 detected ... Check your wiring or I2C ADDR!");
while(1);
}
// initialize servos
panServo.attach(PANSERVO);
tiltServo.attach(TILTSERVO);
// initialize thrusters
thrusters[0].attach(T1);
thrusters[1].attach(T2);
thrusters[2].attach(T3);
thrusters[3].attach(T4);
thrusters[4].attach(T5);
thrusters[5].attach(T6);
thrusters[0].writeMicroseconds(1500);
thrusters[1].writeMicroseconds(1500);
thrusters[2].writeMicroseconds(1500);
thrusters[3].writeMicroseconds(1500);
thrusters[4].writeMicroseconds(1500);
thrusters[5].writeMicroseconds(1500);
delay(1000);
bno.setExtCrystalUse(true);
}
void print_orientation(sensors_event_t event) {
Serial.print('$');
Serial.print(event.orientation.x);
Serial.print(';');
Serial.print(event.orientation.y);
Serial.print(';');
Serial.print(event.orientation.z);
Serial.print(';');
Serial.print('\n');
}
int read_message(struct message *msg) {
if (Serial.available() == 0) {
return 0;
}
int field = 0;
int inChr;
String inString = "";
// Find start
while(true) {
inChr = Serial.read();
if ((char)inChr == '$') {
break;
}
if(Serial.available() == 0) {
return 0;
}
}
while (field < 8) {
while(Serial.available() == 0);
inChr = Serial.read();
if ((char)inChr == ';') {
inString += '\0';
switch(field) {
case 0:
msg->x = inString.toFloat();
break;
case 1:
msg->y = inString.toFloat();
break;
case 2:
msg->z = inString.toFloat();
break;
case 3:
msg->roll = inString.toFloat();
break;
case 4:
msg->pitch = inString.toFloat();
break;
case 5:
msg->yaw = inString.toFloat();
break;
case 6:
msg->cameraTilt = inString.toFloat();
break;
case 7:
msg->cameraPan = inString.toFloat();
break;
}
field++;
inString = "";
} else {
inString += (char) inChr;
}
}
return 1;
}
void thrust(Servo servo, float power)
{
if(power >= 1100 && power <= 1900){
servo.writeMicroseconds(power);
Serial.println(power); //remove line after testing
}
}
void forward(float speed)
{
thrust (thrusters[FRONT_LEFT], speed);
thrust (thrusters[BACK_LEFT], speed);
thrust (thrusters[FRONT_RIGHT], speed);
thrust (thrusters[BACK_RIGHT], speed);
}
void horizontal(float speed)
{
thrust (thrusters[FRONT_LEFT], -1 *speed);
thrust (thrusters[BACK_LEFT], speed);
thrust (thrusters[FRONT_RIGHT], -1 *speed);
thrust (thrusters[BACK_RIGHT], speed);
}
void rotate(float speed)
{
thrust (thrusters[FRONT_LEFT], -1 *speed);
thrust (thrusters[BACK_LEFT], -1 *speed);
thrust (thrusters[FRONT_RIGHT], speed);
thrust (thrusters[BACK_RIGHT], speed);
}
void vertical(float speed)
{
thrust (thrusters[LEFT_MIDDLE], speed);
thrust (thrusters[RIGHT_MIDDLE], speed);
}
void simpleController(struct message *msg) {
forward(msg->x);
horizontal(msg->y);
vertical(msg->z);
rotate(msg->yaw);
}
void loop(void)
{
// get sensor event
sensors_event_t event;
bno.getEvent(&event);
// TODO: run PID
/* Sample: Turn all thrusters on. value has to be in between 1100 and 1900
thrusters[0].writeMicroseconds(1700);
thrusters[1].writeMicroseconds(1700);
thrusters[2].writeMicroseconds(1700);
thrusters[3].writeMicroseconds(1700);
thrusters[4].writeMicroseconds(1700);
thrusters[5].writeMicroseconds(1700); */
if (ticks % TICKS_PER_WRITE == 0) {
//print_orientation(event);
}
// read from Serial
if (read_message(&curMsg)) {
simpleController(&curMsg);
if (curMsg.cameraTilt > 0) {
tiltPos+= 10;
} else if (curMsg.cameraTilt < 0) {
tiltPos-= 10;
}
if (tiltPos > 360) {
tiltPos = 360;
} else if (tiltPos < -180) {
tiltPos = -180;
}
if (curMsg.cameraPan > 0) {
panPos+= 10;
} else if (curMsg.cameraPan < 0) {
panPos-= 10;
}
if (panPos > 360) {
panPos = 360;
} else if (panPos < -180) {
panPos = -180;
}
}
Serial.print(panPos);
Serial.print(" ");
Serial.println(tiltPos);
panServo.writeMicroseconds(1100 + panPos*5);
//tiltServo.write(tiltPos);
delay(500);
ticks++;
}
| 23.389558
| 85
| 0.560783
|
26b207764e6a85b38c85c917291c54edc01720d6
| 1,104
|
ino
|
Arduino
|
src/gauge/gauge.ino
|
jmvalverde2020/Mano-Zeus
|
acb9ca80a7eaf5d53f598bbd65e003142a15d77f
|
[
"CC0-1.0"
] | null | null | null |
src/gauge/gauge.ino
|
jmvalverde2020/Mano-Zeus
|
acb9ca80a7eaf5d53f598bbd65e003142a15d77f
|
[
"CC0-1.0"
] | null | null | null |
src/gauge/gauge.ino
|
jmvalverde2020/Mano-Zeus
|
acb9ca80a7eaf5d53f598bbd65e003142a15d77f
|
[
"CC0-1.0"
] | null | null | null |
#include "ServoM.h"
int SERVOPIN = 6;
int BTNPIN = 2;
ServoM serv1 = ServoM(SERVOPIN);
// Change global variable
int value = 0;
int total = 0;
void setup() {
Serial.begin(9600);
pinMode(BTNPIN, INPUT_PULLUP);
}
void loop() {
// Initial values of each variable
int vel = 5;
int lecturas = 6;
bool push = false;
int time1;
int time2 = millis();
// While the botton is pressed
while (!digitalRead(BTNPIN)){
serv1.start(vel);
push = true;
time1 = millis();
}
// The button is not pressed
serv1.start(0);
// We add the new time value if the button was pressed
if (push){
int result = time1 - time2;
// Serial out
Serial.print("Value: ");
Serial.print(value + 1);
Serial.print("; Reuslt: ");
Serial.println(result);
// Store the time if the value is correct
if (result >= 300){
total+= result;
value++;
}
push = false;
}
delay(10);
// Stops the program
while (value == lecturas){
Serial.print("\nMid time = ");
Serial.println(total/value);
while(1);
}
}
| 16.477612
| 56
| 0.584239
|
5adb5c5ee2ae781a50641720f6ec9eea2bd33722
| 2,679
|
ino
|
Arduino
|
examples/display/display.ino
|
zshivers/arduino-upc
|
dc6cb3f96def869a92b2ce8258020fa2ce3701e4
|
[
"BSD-3-Clause"
] | null | null | null |
examples/display/display.ino
|
zshivers/arduino-upc
|
dc6cb3f96def869a92b2ce8258020fa2ce3701e4
|
[
"BSD-3-Clause"
] | null | null | null |
examples/display/display.ino
|
zshivers/arduino-upc
|
dc6cb3f96def869a92b2ce8258020fa2ce3701e4
|
[
"BSD-3-Clause"
] | null | null | null |
/*
* Show a UPC barcode on a hardware display based on user serial input.
*
* Hardware required:
* - SSD1306 OLED display using SPI pins
*
* Alternatively, you can adapt this code to any display with support
* from Adafruit's GFX library. Your display must be at least 95 pixels
* wide or tall to display a UPC barcode.
*/
#include "UPC.h"
// --- Display specific ---
// Hardware connections for Arduino UNO:
// DC -> Pin 6
// CS -> Pin 7
// RES -> Pin 8
// D0 -> Pin 13
// D1 -> Pin 11
#include <Adafruit_SSD1306.h>
#include <SPI.h>
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define OLED_DC 6
#define OLED_CS 7
#define OLED_RESET 8
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT,
&SPI, OLED_DC, OLED_RESET, OLED_CS);
// --- End Display specific ---
UPC upc;
void setup() {
Serial.begin(115200);
// --- Display specific ---
display.begin(SSD1306_SWITCHCAPVCC);
display.setTextSize(1);
display.setTextColor(WHITE);
display.invertDisplay(true);
// --- End Display specific ---
// display an inital default barcode
String defaultCode = String("01234567890");
updateUPC(defaultCode);
}
bool stringAcceptable(String& str) {
// must be a string of non-zero length with only numbers
if(str.length() == 0) return false;
for(int i = 0; i < str.length(); ++i)
if(!isDigit(str[i])) return false;
return true;
}
void loop() {
String user_input = Serial.readStringUntil('\n');
user_input.trim();
if(stringAcceptable(user_input)) {
updateUPC(user_input);
}
delay(10);
}
void updateUPC(String& input) {
upc.generate(input.c_str());
display.clearDisplay();
drawUPCwithLabel(upc);
display.display();
}
void drawUPCwithLabel(UPC& upc) {
// get the height and width of text
String text = String(upc.text());
int16_t x1, y1; // not used
uint16_t text_width, text_height;
display.getTextBounds(text, 0, 0, &x1, &y1, &text_width, &text_height);
// calculate the bar code coordinates
const int barcode_height = 32;
int barcode_x = (SCREEN_WIDTH - upc.lineCount()) / 2;
int barcode_y = (SCREEN_HEIGHT - barcode_height - (text_height + 6)) / 2;
// draw barcode, centered to screen
// this is done by drawing a vertical bar at each index of the UPC
// generated pattern array
uint8_t* pattern = upc.pattern();
for(int x = 0; x < upc.lineCount(); x++) {
if(pattern[x] == 1) {
display.writeFastVLine(x + barcode_x, barcode_y, barcode_height, WHITE);
}
}
// draw text of the number in the barcode, centered under barcode
int text_y = barcode_y + barcode_height + 3;
display.setCursor((SCREEN_WIDTH - text_width)/2, text_y);
display.print(text);
}
| 26.524752
| 78
| 0.682344
|
0aeae8b2a60de249cc92acb1a601d3d90bbe2d4f
| 1,668
|
ino
|
Arduino
|
SimonSays/SimonSays.ino
|
harlanhaskins/Arduino-Toys
|
72aaa17724e8380d4b9c9dfd73f3d2eb293a792a
|
[
"MIT"
] | 2
|
2018-12-26T11:31:01.000Z
|
2020-11-15T23:11:16.000Z
|
SimonSays/SimonSays.ino
|
harlanhaskins/Arduino-Toys
|
72aaa17724e8380d4b9c9dfd73f3d2eb293a792a
|
[
"MIT"
] | null | null | null |
SimonSays/SimonSays.ino
|
harlanhaskins/Arduino-Toys
|
72aaa17724e8380d4b9c9dfd73f3d2eb293a792a
|
[
"MIT"
] | null | null | null |
#include "ArduinoUtils.h"
DigitalInputPin buttons[3] = {
{2}, {3}, {4}
};
DigitalOutputPin leds[3] = {
{5}, {6}, {7}
};
#define NUM_MOVES 24
void setup() {
randomSeed(analogRead(0));
reset();
}
uint8_t randomMove() {
return random(0, 3);
}
int moves[NUM_MOVES];
int currentMove = 0;
#define forEachMove(stmts) \
for (int i = 0; i < currentMove; ++i) { \
auto move = moves[i]; \
stmts \
}
void reset() {
currentMove = 0;
}
void lightPin(int idx) {
leds[idx].high();
delay(500);
leds[idx].low();
delay(500);
}
void showMoves() {
forEachMove({
lightPin(move);
});
}
void dump() {
Serial << "current move is " << currentMove << "\n";
Serial << "moves: [";
bool isFirst = true;
forEachMove({
if (!isFirst) { Serial << ", "; }
isFirst = false;
Serial << move;
})
Serial << "]\n";
}
void readMoves() {
int current = 0;
while (current < currentMove) {
for (int i = 0; i < 3; ++i) {
DigitalInputPin button = buttons[i];
if (!button.isHigh()) continue;
DigitalOutputPin led = leds[i];
led.high();
while (button.isHigh()) { delay(1); }
led.low();
if (moves[current] != button.pinNum) {
showFailure();
reset();
return;
}
++current;
break;
}
}
}
void showFailure() {
Serial << "FAIL\n";
for (int i = 0; i < 3; ++i) {
leds[0].high();
leds[1].high();
leds[2].high();
delay(200);
leds[0].low();
leds[1].low();
leds[2].low();
delay(200);
}
}
void loop() {
moves[currentMove] = randomMove();
currentMove += 1;
dump();
showMoves();
readMoves();
delay(1000);
}
| 16.038462
| 54
| 0.532974
|
57d5e93c3474d0c85e62ffe718a1544bb168acde
| 14,134
|
ino
|
Arduino
|
Lysring3.ino
|
kagjerde/Arduino-Macro-Ring
|
453ec6d0d6cbde3ae527ceff60aa1dfa5d32ddfe
|
[
"MIT"
] | null | null | null |
Lysring3.ino
|
kagjerde/Arduino-Macro-Ring
|
453ec6d0d6cbde3ae527ceff60aa1dfa5d32ddfe
|
[
"MIT"
] | null | null | null |
Lysring3.ino
|
kagjerde/Arduino-Macro-Ring
|
453ec6d0d6cbde3ae527ceff60aa1dfa5d32ddfe
|
[
"MIT"
] | null | null | null |
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#include <avr/power.h>
#endif
#define PIN 8 //for LED strip
#define NUM_LEDS 24
#define BRIGHTNESS 255
// Rotary encoder declarations
static int pinA = 2; // Our first hardware interrupt pin is digital pin 2
static int pinB = 3; // Our second hardware interrupt pin is digital pin 3
volatile byte aFlag = 0; // let's us know when we're expecting a rising edge on pinA to signal that the encoder has arrived at a detent
volatile byte bFlag = 0; // let's us know when we're expecting a rising edge on pinB to signal that the encoder has arrived at a detent (opposite direction to when aFlag is set)
volatile byte encoderPos = 0; //this variable stores our current value of encoder position. Change to int or uin16_t instead of byte if you want to record a larger range than 0-255
volatile byte oldEncPos = 0; //stores the last encoder position value so we can compare to the current reading and see if it has changed (so we know when to print to the serial monitor)
volatile byte reading = 0; //somewhere to store the direct values we read from our interrupt pins before checking to see if we have moved a whole detent
volatile byte myoldEncPos = 0; //stores the last encoder position v
// Button reading, including debounce without delay function declarations
const byte buttonPin = 13; // this is the Arduino pin we are connecting the push button to
byte oldButtonState = HIGH; // assume switch open because of pull-up resistor
const unsigned long debounceTime = 150; // milliseconds
unsigned long buttonPressTime; // when the switch last changed state
boolean buttonPressed = 0; // a flag variable
// Menu and submenu/setting declarations
byte Mode = 0; // This is which menu mode we are in at any given time (top level or one of the submenus)
const byte modeMax = 5; // This is the number of submenus/settings you want
// Menu system variables
int menuitem = 1;
int frame = 1;
int page = 1;
int lastMenuItem = 1;
boolean firstTime = true;
boolean encoderChange = false;
byte R,G,B;
byte mode3value;
long ledArray = 0xffffff;
long result;
byte bitIndex;
Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUM_LEDS, PIN, NEO_GRB + NEO_KHZ800);
byte neopix_gamma[] = {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2,
2, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5,
5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 9, 9, 9, 10,
10, 10, 11, 11, 11, 12, 12, 13, 13, 13, 14, 14, 15, 15, 16, 16,
17, 17, 18, 18, 19, 19, 20, 20, 21, 21, 22, 22, 23, 24, 24, 25,
25, 26, 27, 27, 28, 29, 29, 30, 31, 32, 32, 33, 34, 35, 35, 36,
37, 38, 39, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 50,
51, 52, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 66, 67, 68,
69, 70, 72, 73, 74, 75, 77, 78, 79, 81, 82, 83, 85, 86, 87, 89,
90, 92, 93, 95, 96, 98, 99,101,102,104,105,107,109,110,112,114,
115,117,119,120,122,124,126,127,129,131,133,135,137,138,140,142,
144,146,148,150,152,154,156,158,160,162,164,167,169,171,173,175,
177,180,182,184,186,189,191,193,196,198,200,203,205,208,210,213,
215,218,220,223,225,228,231,233,236,239,241,244,247,249,252,255 };
int num_array[10][7] = { { 1,1,1,1,1,1,0 }, // 0 //connected as abcdefg
{ 0,1,1,0,0,0,0 }, // 1
{ 1,1,0,1,1,0,1 }, // 2
{ 1,1,1,1,0,0,1 }, // 3
{ 0,1,1,0,0,1,1 }, // 4
{ 1,0,1,1,0,1,1 }, // 5
{ 1,0,1,1,1,1,1 }, // 6
{ 1,1,1,0,0,0,0 }, // 7
{ 1,1,1,1,1,1,1 }, // 8
{ 1,1,1,0,0,1,1 }}; // 9
void setup() {
Serial.begin(9600); // DEBUGGING: opens serial port, sets data rate to 9600 bps
//Display init
pinMode(4,OUTPUT);
pinMode(5,OUTPUT);
pinMode(6,OUTPUT);
pinMode(7,OUTPUT);
pinMode(9,OUTPUT);
pinMode(10,OUTPUT);
pinMode(11,OUTPUT);
Num_Write(0);
//Rotary encoder section of setup
pinMode(pinA, INPUT_PULLUP); // set pinA as an input, pulled HIGH to the logic voltage (5V or 3.3V for most cases)
pinMode(pinB, INPUT_PULLUP); // set pinB as an input, pulled HIGH to the logic voltage (5V or 3.3V for most cases)
attachInterrupt(0,PinA,RISING); // set an interrupt on PinA, looking for a rising edge signal and executing the "PinA" Interrupt Service Routine (below)
attachInterrupt(1,PinB,RISING); // set an interrupt on PinB, looking for a rising edge signal and executing the "PinB" Interrupt Service Routine (below)
// button section of setup
pinMode (buttonPin, INPUT); // setup the button pin
// This is for Trinket 5V 16MHz, you can remove these three lines if you are not using a Trinket
#if defined (__AVR_ATtiny85__)
if (F_CPU == 16000000) clock_prescale_set(clock_div_1);
#endif
// End of trinket special code
strip.setBrightness(BRIGHTNESS);
strip.begin();
strip.show(); // Initialize all pixels to 'off'
}
void loop() {
rotaryMenu();
Num_Write(Mode);
strip.show();
}
void rotaryMenu() { //This handles the bulk of the menu functions without needing to install/include/compile a menu library
//DEBUGGING: Rotary encoder update display if turned
if(oldEncPos != encoderPos) { // DEBUGGING
//Serial.println(encoderPos);// DEBUGGING. Sometimes the serial monitor may show a value just outside modeMax due to this function. The menu shouldn't be affected.
encoderChange = true;
oldEncPos = encoderPos;// DEBUGGING
}// DEBUGGING
// Button reading with non-delay() debounce - thank you Nick Gammon!
byte buttonState = digitalRead (buttonPin);
if (buttonState != oldButtonState){
if (millis () - buttonPressTime >= debounceTime){ // debounce
buttonPressTime = millis (); // when we closed the switch
oldButtonState = buttonState; // remember for next time
if (buttonState == LOW){
//Serial.println ("Button closed"); // DEBUGGING: print that button has been closed
buttonPressed = 1;
}
else {
//Serial.println ("Button opened"); // DEBUGGING: print that button has been opened
buttonPressed = 0;
}
} // end if debounce time up
} // end of state change
//Main menu section
if (Mode == 0 && buttonPressed) {
Mode++; // set the Mode to the current value of input if button has been pressed
firstTime = true;
buttonPressed = 0; // reset the button status so one press results in one action
}
if (Mode == 1 && buttonPressed) {
Mode++; // set the Mode to the current value of input if button has been pressed
firstTime = true;
buttonPressed = 0; // reset the button status so one press results in one action
}
if (Mode == 2 && buttonPressed) {
Mode++; // set the Mode to the current value of input if button has been pressed
firstTime = true;
buttonPressed = 0; // reset the button status so one press results in one action
}
if (Mode == 3 && buttonPressed){
Mode++; // set the Mode to the current value of input if button has been pressed
firstTime = true;
buttonPressed = 0; // reset the button status so one press results in one action
}
if (Mode == 4 && buttonPressed){
Mode++; // set the Mode to the current value of input if button has been pressed
firstTime = true;
buttonPressed = 0; // reset the button status so one press results in one action
}
if (Mode == 5 && buttonPressed){
Mode = 0; // set the Mode to the current value of input if button has been pressed
firstTime = true;
buttonPressed = 0; // reset the button status so one press results in one action
}
if (Mode == 0) {
if(firstTime == true) {
firstTime = false;
encoderPos=51;
result=ledArray;
ledArray = 0xffffff;
R=255;G=255;B=255;
}
else {
int level;
level = encoderPos*5;
if(level>255) level=255;
if(level<5) level=1;
strip.setBrightness(level);
}
}
if (Mode == 1) {
if(firstTime == true) {
//Serial.println("Mode1");
firstTime = false;
encoderPos=0;
}
else {
if (encoderChange==true) {
if(encoderPos>250) encoderPos=0;
else if(encoderPos>7) encoderPos=7;
switch (encoderPos) {
case 0: R=255;G=255;B=255;
break;
case 1: R=250;G=250;B=210;
break;
case 2: R=255;G=255;B=224;
break;
case 3: R=0;G=0;B=255;
break;
case 4: R=255;G=0;B=0;
break;
case 5: R=0;G=255;B=0;
break;
case 6: R=0;G=0;B=255;
break;
case 7: R=random(255);G=random(255);B=random(255);
break;
}
encoderChange=false;
}
}
}
if (Mode == 2) {
if(firstTime == true) {
//Serial.println("Mode2");
firstTime = false;
encoderPos=0;
myoldEncPos=0;
bitIndex=0;
//result=ledArray;
//Serial.println(ledArray,BIN);//DEBUGGING
//Serial.println(encoderPos);//DEBUGGING
}
else {
//Serial.println(bitIndex);//DEBUGGING
//Serial.println("over");//DEBUGGING
if((encoderPos>myoldEncPos)&&!(encoderPos>250)) {
bitClear(ledArray,bitIndex);
bitIndex++;
if(bitIndex>(NUM_LEDS)) bitIndex=NUM_LEDS-1;
encoderPos=bitIndex;
myoldEncPos=encoderPos;
//Serial.println(ledArray,BIN);//DEBUGGING
}
if((encoderPos<myoldEncPos)||(encoderPos>250)) {
bitSet(ledArray,bitIndex);
bitIndex--;
if(bitIndex>250) bitIndex=0;
encoderPos=bitIndex;
myoldEncPos=encoderPos;
//Serial.println(ledArray,BIN);//DEBUGGING
}
}
}
if (Mode == 3) {
if(firstTime == true) {
firstTime = false;
bitIndex=0;
encoderPos=0;
myoldEncPos=0;
}
else {
boolean set;
if((encoderPos>myoldEncPos)&&!(encoderPos>250)) {
if(bitRead(ledArray,0)==1) set=true;
else set=false;
ledArray=ledArray>>1;
if(set) bitSet(ledArray,23);
else bitClear(ledArray,23);
bitIndex++;
if(bitIndex>(NUM_LEDS)) bitIndex=NUM_LEDS-1;
encoderPos=bitIndex;
myoldEncPos=encoderPos;
//Serial.println(ledArray,BIN);//DEBUGGING
}
if((encoderPos<myoldEncPos)||(encoderPos>250)) {
if(bitRead(ledArray,23)==1)set=true;
else set=false;
ledArray=ledArray<<1;
if (set) bitSet(ledArray,0);
else bitClear(ledArray,0);
bitIndex--;
if(bitIndex>250) bitIndex=0;
encoderPos=bitIndex;
myoldEncPos=encoderPos;
//Serial.println(ledArray,BIN);//DEBUGGING
}
}
}
if (Mode == 4) {
ledArray=0b100000000000100000000000;
//100000000011111111111111
}
if (Mode == 5) {
ledArray=0b100000100000100000100000;
}
for(int j = 0; j < 256 ; j++){
for(uint16_t i=0; i<strip.numPixels(); i++) {
if(bitRead(ledArray,i)==1){
strip.setPixelColor(i, strip.Color(R,G,B,neopix_gamma[j] ) );
}
else {
strip.setPixelColor(i, strip.Color(0,0,0,neopix_gamma[j] ) );
}
//result=ledArray>>1;
}
}
}
// this functions writes values to the sev seg pins
void Num_Write(int number)
{
int pin= 4;
for (int j=0; j < 7; j++) {
digitalWrite(pin, num_array[number][j]);
pin++;
if(pin==8) {pin++;}
}
}
//-------------------------------------------------------------------------------------Rotary Encoder-----------------------------------------------------
//Rotary encoder interrupt service routine for one encoder pin
void PinA(){
cli(); //stop interrupts happening before we read pin values
reading = PIND & 0xC; // read all eight pin values then strip away all but pinA and pinB's values
if(reading == B00001100 && aFlag) { //check that we have both pins at detent (HIGH) and that we are expecting detent on this pin's rising edge
encoderPos --; //decrement the encoder's position count
bFlag = 0; //reset flags for the next turn
aFlag = 0; //reset flags for the next turn
}
else if (reading == B00000100) bFlag = 1; //signal that we're expecting pinB to signal the transition to detent from free rotation
sei(); //restart interrupts
}
//Rotary encoder interrupt service routine for the other encoder pin
void PinB(){
cli(); //stop interrupts happening before we read pin values
reading = PIND & 0xC; //read all eight pin values then strip away all but pinA and pinB's values
if (reading == B00001100 && bFlag) { //check that we have both pins at detent (HIGH) and that we are expecting detent on this pin's rising edge
encoderPos ++; //increment the encoder's position count
bFlag = 0; //reset flags for the next turn
aFlag = 0; //reset flags for the next turn
}
else if (reading == B00001000) aFlag = 1; //signal that we're expecting pinA to signal the transition to detent from free rotation
sei(); //restart interrupts
}
| 39.814085
| 191
| 0.57436
|
929461986f5d6f36729bd76b0c5d2aead40271c7
| 2,803
|
ino
|
Arduino
|
togetherwheelmotor.ino
|
exquire/togetherwheel
|
abdbaf1a18c23d9ce3401b4be2835918f301c21b
|
[
"Unlicense"
] | null | null | null |
togetherwheelmotor.ino
|
exquire/togetherwheel
|
abdbaf1a18c23d9ce3401b4be2835918f301c21b
|
[
"Unlicense"
] | null | null | null |
togetherwheelmotor.ino
|
exquire/togetherwheel
|
abdbaf1a18c23d9ce3401b4be2835918f301c21b
|
[
"Unlicense"
] | null | null | null |
#include "DualVNH5019MotorShield.h"
DualVNH5019MotorShield md;
#include <Encoder.h>
Encoder myEnc(2, 3);
// set pin numbers:
const int buttonPin = 5; // the number of the pushbutton pin
const int ledPin = 13; // the number of the LED pin
// variables will change:
int buttonState = 0; // variable for reading the pushbutton status
unsigned long storedMillis;
int encCount;
float RPS;
float desiredRPS = 0;
int totalRotations;
int storedRotations;
int motorSpeed = 0;
float motorSpeedA = 30;
int pwmPin = A0;
int pwmVal = 0;
float encRes = 28; // This is the 'pulses per revolution' which can vary between encoders.
float gearDiv =4 ; // This is the Gear ration as a divisor. i.e. A gear reduction ration of 4:1 is a divisor of 4.
float PulleyDrive = 27; // Number of teeth, or circle diameter of pulley attach to Drive/Motor shaft;
float PulleyAxle = 60; // Number of teeth, or circle diameter of pulley attach to Axle;
float reduction = 0;
int TotalEncCount = 0;
void setup()
{
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT);
Serial.begin(4800);
md.init(); // required for Pololu 33926 Libary
reduction = (encRes*gearDiv)/(PulleyAxle/PulleyDrive);
}
void loop(){
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);
// check if the pushbutton is pressed.
// if it is, the buttonState is HIGH:
if (buttonState == HIGH) {
// turn LED on:
digitalWrite(ledPin, HIGH);
desiredRPS = 9.166;
} else {
// turn LED off:
digitalWrite(ledPin, LOW);
desiredRPS = 3;
}
{
pwmVal = analogRead(pwmPin);
motorSpeed = map(pwmVal, 0, 1064, 0, 255);
md.setM2Speed(-motorSpeedA);
}
{
TotalEncCount = myEnc.read();
unsigned long NewMillis = millis();
if (NewMillis - storedMillis > (125)) // every eighth of 1 second
{
encCount = (TotalEncCount - storedRotations); // the count for that second is the new rotation amount, minus the old rotation amount.
// uncomment to report total Rotations per second
storedRotations = TotalEncCount;
storedMillis = NewMillis;
if (encCount >= 0)
{
if (RPS > (desiredRPS) && motorSpeedA > 0) motorSpeedA--;
if (RPS <= (desiredRPS) && motorSpeedA < 160) motorSpeedA++;
}
if (encCount < 0)
{
if (RPS > (-desiredRPS) && motorSpeedA > 0) motorSpeedA++;
if (RPS < (-desiredRPS) && motorSpeedA < 160) motorSpeedA--;
}
Serial.print("Detected RPS: ");
Serial.println(RPS);
Serial.print("Output Speed: ");
Serial.println(motorSpeedA);
Serial.print("Desired RPS: ");
Serial.println(desiredRPS);
}
}
RPS = (encCount/reduction*8);
}
| 21.728682
| 139
| 0.658937
|
559db299178224365e4ce4d9caacd7de838f7c6e
| 5,066
|
ino
|
Arduino
|
distance_and_temperature/distance_and_temperature.ino
|
kartoza/arduino
|
68960128a1ce15360ccf37498f17640d67fdd39e
|
[
"MIT"
] | null | null | null |
distance_and_temperature/distance_and_temperature.ino
|
kartoza/arduino
|
68960128a1ce15360ccf37498f17640d67fdd39e
|
[
"MIT"
] | null | null | null |
distance_and_temperature/distance_and_temperature.ino
|
kartoza/arduino
|
68960128a1ce15360ccf37498f17640d67fdd39e
|
[
"MIT"
] | 2
|
2016-06-03T10:28:34.000Z
|
2019-05-26T06:14:09.000Z
|
#include <LiquidCrystal_I2C.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include "Arduino.h"
class Ultrasonic
{
public:
Ultrasonic(int pin);
void DistanceMeasure(void);
long microsecondsToCentimeters(void);
private:
int _pin; //pin number of Arduino that is connected with SIG pin of Ultrasonic Ranger.
long duration; // the Pulse time received;
};
Ultrasonic::Ultrasonic(int pin)
{
_pin = pin;
}
/*Begin the detection and get the pulse back signal*/
void Ultrasonic::DistanceMeasure(void)
{
pinMode(_pin, OUTPUT);
digitalWrite(_pin, LOW);
delayMicroseconds(2);
digitalWrite(_pin, HIGH);
delayMicroseconds(5);
digitalWrite(_pin, LOW);
pinMode(_pin, INPUT);
duration = pulseIn(_pin, HIGH);
}
/*The measured distance from the range 0 to 400 Centimeters*/
long Ultrasonic::microsecondsToCentimeters(void)
{
return duration / 29 / 2;
}
// Data wire is plugged into port 2 on the Arduino
#define ONE_WIRE_BUS 2
// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temp_celciuserature ICs)
OneWire oneWire(ONE_WIRE_BUS);
// Pass our oneWire reference to Dallas temp_celciuserature.
DallasTemperature sensors(&oneWire);
int RED_LED = 8;
int YELLOW_LED = 9;
// Set the LCD I2C address
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
Ultrasonic ultrasonic(10);
long BASELINE_DISTANCE = 0.0;
long DISTANCE_CHANGE_COUNT = 0;
//allow for cm variations in distance without triggering
long TOLERANCE = 20;
// maximum distance sensor can detect in cm
long MAX_DISTANCE = 551;
// used for keeping track of the last recorded temperature
float LAST_TEMP = 0.0;
// used for keeping track of the last recorded distance
double LAST_DISTANCE = 0;
void setup(void)
{
// start serial port
Serial.begin(9600);
pinMode(RED_LED, OUTPUT);
pinMode(YELLOW_LED, OUTPUT);
sensors.begin();
lcd.begin(16, 2); // initialize the lcd for 16 chars 2 lines, turn on backlight
// ------- Quick 3 blinks of backlight -------------
for (int i = 0; i < 3; i++)
{
lcd.backlight();
delay(250);
lcd.noBacklight();
delay(250);
}
lcd.backlight(); // finish with backlight on
lcd.setCursor(0, 0); //Start at character 4 on line 0
lcd.print("Initialising");
lcd.setCursor(0, 1); //col, row
lcd.print("distance...");
delay(3000);
ultrasonic.DistanceMeasure();// get the current signal time;
BASELINE_DISTANCE = ultrasonic.microsecondsToCentimeters();
lcd.clear();
lcd.print("Baseline: ");
lcd.print(BASELINE_DISTANCE);
lcd.print("cm");
delay(3000);
}
void loop(void)
{
// get the current signal time;
ultrasonic.DistanceMeasure();
//convert the time to centimeters
long range_in_cm = ultrasonic.microsecondsToCentimeters();
// Send the command to get temperature
sensors.requestTemperatures();
float temp_celcius = sensors.getTempCByIndex(0);
// short circuit if there is no status change
if (( temp_celcius == LAST_TEMP) && ( range_in_cm == LAST_DISTANCE ))
{
// do nothing - avoid doing any other processing to reduce
// latency
}
else if (
((BASELINE_DISTANCE - TOLERANCE) > range_in_cm) &&
(range_in_cm < MAX_DISTANCE))
{
DISTANCE_CHANGE_COUNT += 1;
Serial.print("Count: ");
Serial.println(DISTANCE_CHANGE_COUNT);
show_movement_leds();
update_display(temp_celcius, range_in_cm);
}
else
{
update_display(temp_celcius, range_in_cm);
// to reduce latency we will only update temperature leds
// if there was no movement change
show_temperature_leds(temp_celcius);
}
LAST_TEMP = temp_celcius;
LAST_DISTANCE = range_in_cm;
}
void update_display(float temp_celcius, double distance_cm)
{
lcd.clear();
lcd.print(temp_celcius);
lcd.print(" degrees");
lcd.setCursor(0, 1); //col, row
lcd.print(DISTANCE_CHANGE_COUNT);
lcd.print(" (");
lcd.print(distance_cm);
lcd.print(" cm)");
}
/* Provide some visual feedback when a movement has been
* detected by the distance sensor.
*/
void show_movement_leds()
{
// turn the LED on (HIGH is the voltage level)
digitalWrite(RED_LED, HIGH);
// turn the LED off (LOW is the voltage level)
digitalWrite(YELLOW_LED, LOW);
}
/* Show status indicators using leds if the
* temperature has changed between different thresholds.
*/
void show_temperature_leds(float temp_celcius)
{
float threshold = 30.0; //degrees celcius
if ( temp_celcius > threshold )
{
lcd.backlight();
digitalWrite(RED_LED, HIGH); // turn the LED on (HIGH is the voltage level)
digitalWrite(YELLOW_LED, LOW); // turn the LED off (LOW is the voltage level)
}
else if (temp_celcius == threshold)
{
digitalWrite(RED_LED, HIGH); // turn the LED off (LOW is the voltage level)
digitalWrite(YELLOW_LED, HIGH); // turn the LED on (HIGH is the voltage level)
}
else
{
lcd.noBacklight();
digitalWrite(RED_LED, LOW); // turn the LED off (LOW is the voltage level)
digitalWrite(YELLOW_LED, HIGH); // turn the LED on (HIGH is the voltage level)
}
}
| 28.301676
| 115
| 0.70154
|
a85a8f3df420e4b6843bf840dead904d16dfe88c
| 2,318
|
ino
|
Arduino
|
Tablet-pdf-music-pedal.ino
|
leonvandenbeukel/Tablet-pdf-music-pedal
|
81b9c440d0535aaacdfddba8ef4676d2aafa10f3
|
[
"MIT"
] | null | null | null |
Tablet-pdf-music-pedal.ino
|
leonvandenbeukel/Tablet-pdf-music-pedal
|
81b9c440d0535aaacdfddba8ef4676d2aafa10f3
|
[
"MIT"
] | null | null | null |
Tablet-pdf-music-pedal.ino
|
leonvandenbeukel/Tablet-pdf-music-pedal
|
81b9c440d0535aaacdfddba8ef4676d2aafa10f3
|
[
"MIT"
] | 1
|
2019-10-24T23:21:02.000Z
|
2019-10-24T23:21:02.000Z
|
#include <Bounce2.h>
#include "Keyboard.h"
#define BUTTON_PIN_LEFT 14
#define LED_PIN_LEFT 9
#define BUTTON_PIN_RIGHT 15
#define LED_PIN_RIGHT 10
#define LED_POWER 8
// Keys reference: https://github.com/arduino-libraries/Keyboard/blob/master/src/Keyboard.h
#define PREV_PAGE KEY_LEFT_ARROW
#define NEXT_PAGE KEY_RIGHT_ARROW
// Instantiate a Bounce object
Bounce debouncer_left = Bounce();
Bounce debouncer_right = Bounce();
// The current buttonState_left
// 0 : released
// 1 : pressed less than 2 seconds
// 2 : pressed longer than 2 seconds
int buttonState_left;
unsigned long buttonPressTimeStamp_left;
int buttonState_right;
unsigned long buttonPressTimeStamp_right;
void setup() {
Serial.begin(57600);
// Setup the button
pinMode(BUTTON_PIN_LEFT, INPUT);
pinMode(BUTTON_PIN_RIGHT, INPUT);
// Activate internal pull-up
digitalWrite(BUTTON_PIN_LEFT, HIGH);
digitalWrite(BUTTON_PIN_RIGHT, HIGH);
// After setting up the button, setup debouncer_left
debouncer_left.attach(BUTTON_PIN_LEFT);
debouncer_right.attach(BUTTON_PIN_RIGHT);
debouncer_left.interval(5);
debouncer_right.interval(5);
//Setup the LEDs
pinMode(LED_PIN_LEFT, OUTPUT);
pinMode(LED_PIN_RIGHT, OUTPUT);
pinMode(LED_POWER, OUTPUT);
digitalWrite(LED_POWER, HIGH);
Keyboard.begin();
}
void loop() {
// Update the debouncer_left and get the changed state
boolean changed_left = debouncer_left.update();
boolean changed_right = debouncer_right.update();
if (changed_left) {
// Get the update value
int value = debouncer_left.read();
if (value == HIGH) {
digitalWrite(LED_PIN_LEFT, LOW);
buttonState_left = 0;
Serial.println("Button released (state 0)");
}
else {
digitalWrite(LED_PIN_LEFT, HIGH);
Keyboard.write(PREV_PAGE);
buttonState_left = 1;
Serial.println("Button pressed (state 1)");
buttonPressTimeStamp_left = millis();
}
}
if (changed_right) {
// Get the update value
int value = debouncer_right.read();
if (value == HIGH) {
digitalWrite(LED_PIN_RIGHT, LOW);
buttonState_right = 0;
Serial.println("Button released right (state 0)");
}
else {
digitalWrite(LED_PIN_RIGHT, HIGH);
Keyboard.write(NEXT_PAGE);
buttonState_right = 1;
Serial.println("Button pressed right (state 1)");
buttonPressTimeStamp_right = millis();
}
}
}
| 23.18
| 91
| 0.738568
|
d9a34f786d9f478a4b51c1744e34e580c5dc43eb
| 7,499
|
ino
|
Arduino
|
01.Firmware/components/FabGL/examples/VGA/DirectVGA_ElMuro/DirectVGA_ElMuro.ino
|
POMIN-163/xbw
|
ebda2fb925ec54e48e806ba1c3cd4e04a7b25368
|
[
"Apache-2.0"
] | 5
|
2022-02-14T03:12:57.000Z
|
2022-03-06T11:58:31.000Z
|
01.Firmware/components/FabGL/examples/VGA/DirectVGA_ElMuro/DirectVGA_ElMuro.ino
|
POMIN-163/xbw
|
ebda2fb925ec54e48e806ba1c3cd4e04a7b25368
|
[
"Apache-2.0"
] | null | null | null |
01.Firmware/components/FabGL/examples/VGA/DirectVGA_ElMuro/DirectVGA_ElMuro.ino
|
POMIN-163/xbw
|
ebda2fb925ec54e48e806ba1c3cd4e04a7b25368
|
[
"Apache-2.0"
] | 4
|
2022-02-23T07:00:59.000Z
|
2022-03-10T03:58:11.000Z
|
/*
Created by Fabrizio Di Vittorio (fdivitto2013@gmail.com) - www.fabgl.com
Copyright (c) 2019-2020 Fabrizio Di Vittorio.
All rights reserved.
This file is part of FabGL Library.
FabGL is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
FabGL is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FabGL. If not, see <http://www.gnu.org/licenses/>.
*/
#include "fabgl.h"
fabgl::VGADirectController DisplayController;
fabgl::PS2Controller PS2Controller;
SoundGenerator soundGenerator;
SquareWaveformGenerator swg;
#include "controllers.h"
#include "soundchip.h"
#define TOPMARGIN 6
#define SIDEMARGIN 14
#define INITIALDIR (-PI/2+.5)
#define INITIALY 180
#define INITIALX 150
#define PADDLES 3
volatile double objX = INITIALX;
volatile double objY = INITIALY;
static double objDir = INITIALDIR;
static double objVel = 4;
static constexpr int objSize = 8;
static TaskHandle_t mainTaskHandle;
static uint32_t bgParkMillerState = 1;
long offGame = 0;
// just to avoid floating point calculations inside MyDirectDrawVGAController::drawScanline()
volatile int objIntX;
volatile int objIntY;
int nBricks = 0;
bool brickMap[8][12];
int paddlePos = 320/2;
int nPaddles = PADDLES;
GameControllerMouse cMouse;
GameControllerKeys cKeysArrows;
inline int fastRandom()
{
bgParkMillerState = (uint64_t)bgParkMillerState * 48271 % 0x7fffffff;
return bgParkMillerState % 4;
}
void IRAM_ATTR drawScanline(void * arg, uint8_t * dest, int scanLine)
{
auto fgcolor = DisplayController.createRawPixel(RGB222(3, 3, 3));
auto white = DisplayController.createRawPixel(RGB222(3, 3, 3));
auto black = DisplayController.createRawPixel(RGB222(0, 0, 0));
auto bgcolor = DisplayController.createRawPixel(RGB222(0, 0, 0));
if( scanLine >= 32 )
{
if(scanLine < 32+16)
{
bgcolor = DisplayController.createRawPixel(RGB222(1, 0, 0));
fgcolor = DisplayController.createRawPixel(RGB222(3, 0, 0));
}
else if(scanLine < 32+16+16)
{
bgcolor = DisplayController.createRawPixel(RGB222(1, 0, 1));
fgcolor = DisplayController.createRawPixel(RGB222(3, 0, 3));
}
else if(scanLine < 32+16+16+16)
{
bgcolor = DisplayController.createRawPixel(RGB222(0, 1, 0));
fgcolor = DisplayController.createRawPixel(RGB222(0, 3, 0));
}
else if(scanLine < 32+16+16+16+16)
{
bgcolor = DisplayController.createRawPixel(RGB222(1, 1, 0));
fgcolor = DisplayController.createRawPixel(RGB222(3, 3, 0));
}
}
auto width = DisplayController.getScreenWidth();
// fill line with background color
if( scanLine < TOPMARGIN)
memset(dest+8, fgcolor, width-16);
else
{
memset(dest, black, 16);
memset(dest+319-15, black, 16);
memset(dest+16, bgcolor, width-32);
for( int ncompta = 8; ncompta < SIDEMARGIN; ncompta++)
{
VGA_PIXELINROW(dest, ncompta) = white;
VGA_PIXELINROW(dest, 319-ncompta) = white;
}
}
// fill object with foreground color
if (scanLine >= objIntY - objSize / 2 && scanLine <= objIntY + objSize / 2)
{
for (int col = objIntX - objSize / 2; col < objIntX + objSize / 2; ++col)
VGA_PIXELINROW(dest, col) = fgcolor;
}
if (scanLine >= 184 && scanLine < 192 )
{
for (int col = paddlePos - 16 ; col < paddlePos + 16; ++col)
VGA_PIXELINROW(dest, col) = white;
}
// drawBricks
if( scanLine >= 32 && scanLine < (32+16+16+16+16) && scanLine % 8 != 0)
for( int x = 0; x < 12*3*8; x++)
{
if( x%24 != 0 && x%24 != 23 && brickMap[(scanLine-32)/8][x/24])
VGA_PIXELINROW(dest, x+16) = fgcolor;
}
if( scanLine >= 10 && scanLine <= 13 )
for (int p = 0; p < nPaddles; p++)
for( int x = 0; x < 10; x++)
VGA_PIXELINROW(dest, 300 - x - p*14) = white;
if (scanLine == DisplayController.getScreenHeight() - 1) {
// signal end of screen
vTaskNotifyGiveFromISR(mainTaskHandle, NULL);
}
}
void resetGame()
{
memset( brickMap, true, sizeof(brickMap));
nBricks = 12*8;
objIntX = objX = INITIALX;
objIntY = objY = INITIALY;
objDir = INITIALDIR;
offGame = millis();
nPaddles = PADDLES;
playSoundReset();
}
void setup()
{
Serial.begin(115200); delay(500); Serial.write("\n\n\n"); // DEBUG ONLY
PS2Controller.begin(PS2Preset::KeyboardPort0_MousePort1, KbdMode::GenerateVirtualKeys);
cMouse = GameControllerMouse (0);
cKeysArrows = GameControllerKeys (1, fabgl::VK_UP, fabgl::VK_DOWN, fabgl::VK_LEFT, fabgl::VK_RIGHT, fabgl::VK_RSHIFT, fabgl::VK_ESCAPE);
mainTaskHandle = xTaskGetCurrentTaskHandle();
DisplayController.begin();
DisplayController.setDrawScanlineCallback(drawScanline);
DisplayController.setResolution(VGA_320x200_75Hz);
soundGenerator.setVolume(127);
soundGenerator.play(true);
soundGenerator.attach( &swg);
resetGame();
delay(3000);
}
void loop()
{
if( millis() - offGame > 4000)
offGame = false;
// check brick collision
static int oldbricky = -1;
int brickx = (objIntX-16)/24;
int bricky = (objIntY-32)/8;
if( bricky >= 0 && bricky <8 && brickx < 12 && brickMap[bricky][brickx] )
{
brickMap[bricky][brickx] = false;
nBricks--;
objDir = (( bricky != oldbricky ) ? 2 : 1) * PI - objDir;
playSoundPic();
}
if( nBricks == 0) resetGame();
// test collision with borders and bounce changing direction
if (objX < objSize / 2 +SIDEMARGIN|| objX > DisplayController.getScreenWidth() - objSize / 2-SIDEMARGIN)
{
objDir = PI - objDir;
playSoundPong();
}
else if (objY < objSize / 2 +TOPMARGIN )
{
objDir = 2 * PI - objDir;
playSoundPong();
}
double sdir = sin(objDir);
// check paddle collision
if ( !offGame && objX > paddlePos -(16+objSize/2) && objX < paddlePos +(16+objSize/2) && objY > 184-objSize/2 && objY< 192 && sdir >= 0)
{
objDir = 2 * PI - objDir;
objDir += (objX - ((double)paddlePos))*((PI/2.0)/32.0);
playSoundTuc();
}
if( !offGame )
{
sdir = sin(objDir);
// calculate new coordinates
objX += objVel * cos(objDir);
objY += objVel * sdir;
}
else
objX = paddlePos +8;
if(objY < 7) objY = 8;
if( objX < 16 ) objX = 16 ;
if( objX > 319-16 ) objX = 319-16;
// Ball lost
if(objY > 200)
{
playSoundOut();
offGame = millis();
nPaddles--;
if( nPaddles == -1)
resetGame();
else
{
objY = INITIALY;
objDir = INITIALDIR;
}
}
// convert object coordinate to integer
objIntX = objX;
objIntY = objY;
oldbricky = bricky;
cMouse.update();
paddlePos += cMouse.getDX();
if( cKeysArrows.isLeft() ) paddlePos -= 8;
if( cKeysArrows.isRight() ) paddlePos += 8;
if( cMouse.isButtonA() || cKeysArrows.isButtonA() )
offGame = false;
if( paddlePos < 32) paddlePos = 32;
if( paddlePos > 319-32) paddlePos = 319-32;
// wait for vertical sync
ulTaskNotifyTake(pdTRUE, portMAX_DELAY);
}
| 27.269091
| 138
| 0.643953
|
abc03c9044cbde36a743e120ec99a4d02dec46c0
| 8,183
|
ino
|
Arduino
|
le code/Project/Project.ino
|
ZouhairKhatouri/Tap-controler
|
11ea04d58686c08a55c4990897bd0d932bc2a2c2
|
[
"MIT"
] | null | null | null |
le code/Project/Project.ino
|
ZouhairKhatouri/Tap-controler
|
11ea04d58686c08a55c4990897bd0d932bc2a2c2
|
[
"MIT"
] | null | null | null |
le code/Project/Project.ino
|
ZouhairKhatouri/Tap-controler
|
11ea04d58686c08a55c4990897bd0d932bc2a2c2
|
[
"MIT"
] | null | null | null |
#include <SoftwareSerial.h>
// Global constants
// Step motor:
const int IN1 = 12;
const int IN2 = 11;
const int IN3 = 10;
const int IN4 = 9;
// ESP8266-01:
const int rxESP = 7;
const int txESP = 8;
const int rst = 5;
// HC-05
const int rxBT = 3;
const int txBT = 4;
const int vccBT = 6;
// Led pin
const int isConnected = 2;
// Factory parameters
const String clientID = "SomeID";
const String btPswd = "SomePswd";
// Server parameters
const String server = "tapcontroller.000webhostapp.com";
const String getURI = "/getValue.php";
const String putNewURI = "/putNewID.php";
const String dataPG = "clientID="+clientID;
const String putValueURI = "/putValue.php";
const String dataPV = "clientID="+clientID+"&flow=0&duration=0";
// State variables
String ssid = "";
String pswd = "";
double flow = 0;
long duration = 0;
boolean paired = false;
int failures = 0;
SoftwareSerial ESP(rxESP, txESP);
SoftwareSerial BTSerial(rxBT, txBT);
void setup() {
ESP.begin(9600);
BTSerial.begin(9600);
// disconnect from all access-points
ESP.println("AT+CWJAP=\"\",\"\"");
pinMode(IN1, OUTPUT);
pinMode(IN2, OUTPUT);
pinMode(IN3, OUTPUT);
pinMode(IN4, OUTPUT);
pinMode(isConnected, OUTPUT);
pinMode(vccBT, OUTPUT);
digitalWrite(vccBT, HIGH);
pinMode(rst, OUTPUT);
digitalWrite(rst, HIGH);
}
void loop() {
if(paired){
ESP.listen();
excuteInstruction();
}
else{
BTSerial.listen();
if(BTSerial.available()){
String apData = BTSerial.readString();
int diez = apData.indexOf("#");
if(diez>0){
int i = 0;
while(i<diez){
ssid += apData.charAt(i);
i += 1;
}
i += 1;
while(i<apData.length()){
pswd += apData.charAt(i);
i += 1;
}
paired = true;
digitalWrite(vccBT, LOW);
while(!connectToAP()){
delay(1);
}
httppost(putNewURI,dataPG);
}
}
}
}
void openTheTap(double dflow){
if(flow+dflow > 0 and flow+dflow <= 100){
flow = flow + dflow;
double nbStep = 2048*dflow/100;
stepper(nbStep);
}
return;
}
void closeTheTap(){
double nbStep = -2048*flow/100;
stepper(nbStep);
flow = 0;
duration = 0;
}
// Taken from https://www.aranacorp.com/fr/pilotez-un-moteur-pas-a-pas-avec-arduino/
void stepper(double nbStep){
int Direction;
int Steps = 0;
if(nbStep>=0){
Direction=1;
}
else{
Direction=0;
nbStep=-nbStep;
}
for (int x=0;x<nbStep*8;x++){
switch(Steps){
case 0:
digitalWrite(IN1, LOW);
digitalWrite(IN2, LOW);
digitalWrite(IN3, LOW);
digitalWrite(IN4, HIGH);
break;
case 1:
digitalWrite(IN1, LOW);
digitalWrite(IN2, LOW);
digitalWrite(IN3, HIGH);
digitalWrite(IN4, HIGH);
break;
case 2:
digitalWrite(IN1, LOW);
digitalWrite(IN2, LOW);
digitalWrite(IN3, HIGH);
digitalWrite(IN4, LOW);
break;
case 3:
digitalWrite(IN1, LOW);
digitalWrite(IN2, HIGH);
digitalWrite(IN3, HIGH);
digitalWrite(IN4, LOW);
break;
case 4:
digitalWrite(IN1, LOW);
digitalWrite(IN2, HIGH);
digitalWrite(IN3, LOW);
digitalWrite(IN4, LOW);
break;
case 5:
digitalWrite(IN1, HIGH);
digitalWrite(IN2, HIGH);
digitalWrite(IN3, LOW);
digitalWrite(IN4, LOW);
break;
case 6:
digitalWrite(IN1, HIGH);
digitalWrite(IN2, LOW);
digitalWrite(IN3, LOW);
digitalWrite(IN4, LOW);
break;
case 7:
digitalWrite(IN1, HIGH);
digitalWrite(IN2, LOW);
digitalWrite(IN3, LOW);
digitalWrite(IN4, HIGH);
break;
default:
digitalWrite(IN1, LOW);
digitalWrite(IN2, LOW);
digitalWrite(IN3, LOW);
digitalWrite(IN4, LOW);
break;
}
delayMicroseconds(1000);
if(Direction==1){
Steps++;
}
if(Direction==0){
Steps--;
}
if(Steps>7){
Steps=0;
}
if(Steps<0){
Steps=7;
}
}
}
// Partially taken from https://www.les-electroniciens.com/videos/arduino-ep16-installation-du-module-wifi-esp8266
boolean connectToAP(){
boolean flag = false;
ESP.listen();
ESP.println("AT+CWJAP=\""+ ssid + "\",\"" + pswd +"\"");
delay(3000);
flag = ESP.find("OK");
if(flag){
digitalWrite(isConnected,HIGH);
}
else{
digitalWrite(isConnected,LOW);
}
return flag;
}
// Partially taken from https://www.instructables.com/id/Arduino-Esp8266-Post-Data-to-Website/
String httppost (String uri,String data) {
String response = "";
String postRequest =
"POST " + uri + " HTTP/1.0\r\n" +
"Host: " + server + "\r\n" +
"Accept: *" + "/" + "*\r\n" +
"Content-Length: " + data.length() + "\r\n" +
"Content-Type: application/x-www-form-urlencoded\r\n" +
"\r\n" + data;
String sendCmd = "AT+CIPSEND=";//determine the number of caracters to be sent.
do{
// TCP connexion
do {
connectToAP();
ESP.println("AT+CIPSTART=\"TCP\",\"" + server + "\",80");//start a TCP connection.
failures += 1;
if(failures>10){
wakeUp();
}
}
while(!ESP.find("OK"));
// Sending the length
do{
ESP.print(sendCmd);
ESP.println(postRequest.length() );
delay(500);
failures += 1;
if(failures>10){
wakeUp();
}
}
while(!ESP.find(">"));
// Sending the POST query
ESP.println(postRequest);
failures += 1;
if(failures>10){
wakeUp();
}
}
while(!ESP.find("SEND OK"));
failures = 0;
long int timeout = 3000;
long int t0 = millis();
while ( (t0 + timeout) > millis())
{
while (ESP.available())
{
char c = ESP.read();
response += c;
}
}
// close the connection
ESP.println("AT+CIPCLOSE");
delay(100);
return response;
}
double getData(){
String response = httppost(getURI,dataPG);
int startingStar = response.indexOf("*");
int endingStar = response.indexOf("*",startingStar+1);
int diez = response.indexOf("#");
String printedFlow = "";
String printedDuration = "";
if(startingStar<0 or endingStar<0 or diez<0){
return flow;
}
else{
int buff = startingStar+1;
while(buff<diez){
printedFlow += response.charAt(buff);
buff += 1;
}
buff += 1;
while(buff<endingStar){
printedDuration += response.charAt(buff);
buff += 1;
}
}
if(printedFlow == "F" or printedDuration == "F"){
// Serial.println("This object isn't recorded in the database");
}
else{
char *stopstringDuration;
long durationTmp = strtol(printedDuration.c_str(), &stopstringDuration,0);
if(!(stopstringDuration == printedDuration.c_str())){
duration = durationTmp;
}
char *stopstringFlow;
double flowTmp = strtod(printedFlow.c_str(), &stopstringFlow);
if(!(stopstringFlow == printedFlow.c_str())){
return flowTmp;
}
}
return flow;
}
void excuteInstruction(){
double newFlow = getData();
// init value in server:
httppost(putValueURI,dataPV);
double dflow = newFlow-flow;
openTheTap(dflow);
flow = newFlow;
delay(duration*1000*60);
closeTheTap();
}
void wakeUp(){
digitalWrite(rst,LOW);
delay(100);
digitalWrite(rst,HIGH);
failures = 0;
}
| 22.297003
| 115
| 0.530612
|
7b38377f398559acbc08c5056cc10a2c1a336901
| 890
|
ino
|
Arduino
|
Sketches/LedBlink/LedBlink.ino
|
SirWellington/arduino
|
1d6b301722045902626372421afe4de51e5d1d13
|
[
"Apache-2.0"
] | 1
|
2015-11-10T22:29:53.000Z
|
2015-11-10T22:29:53.000Z
|
Sketches/LedBlink/LedBlink.ino
|
SirWellington/arduino
|
1d6b301722045902626372421afe4de51e5d1d13
|
[
"Apache-2.0"
] | null | null | null |
Sketches/LedBlink/LedBlink.ino
|
SirWellington/arduino
|
1d6b301722045902626372421afe4de51e5d1d13
|
[
"Apache-2.0"
] | null | null | null |
//Communicates with the led on pin 13
/*
* This Sketch Makes an LED Blink a configurable
* amount of times. The LED is expected to be wired on the breadboard,
* on a PIN # 10, although that can be changed as well.
*/
int LED = 10;
int SYSTEM_LED = 13;
void setup()
{
// put your setup code here, to run once:
pinMode(LED, OUTPUT);
pinMode(SYSTEM_LED, OUTPUT);
turnOff(SYSTEM_LED);
}
void loop()
{
blink(LED, 2);
sleep(5);
}
void blink(int led, int numberOfTimes)
{
for(int i = 0; i < numberOfTimes; ++i)
{
turnOn(led);
sleep(0.1);
turnOff(led);
sleep(0.1);
}
}
void sleep(double seconds)
{
int milliseconds = secondsToMillis(seconds);
delay(milliseconds);
}
int secondsToMillis(double seconds)
{
return seconds * 1000;
}
void turnOn(int device)
{
digitalWrite(device, HIGH);
}
void turnOff(int device)
{
digitalWrite(device, LOW);
}
| 15.892857
| 70
| 0.664045
|
b887b061539394207f6ad244b8df56e7057f6093
| 1,555
|
ino
|
Arduino
|
SN74HC595N/exampleCodeLibrary.ino
|
arnox86/ProjectWeatherStation
|
062b9efdac576acb4fbf096c8dd3517a39f35848
|
[
"MIT"
] | null | null | null |
SN74HC595N/exampleCodeLibrary.ino
|
arnox86/ProjectWeatherStation
|
062b9efdac576acb4fbf096c8dd3517a39f35848
|
[
"MIT"
] | null | null | null |
SN74HC595N/exampleCodeLibrary.ino
|
arnox86/ProjectWeatherStation
|
062b9efdac576acb4fbf096c8dd3517a39f35848
|
[
"MIT"
] | null | null | null |
/*
MIT License
Copyright (c) 2020 Benedikt Bursian
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include <shiftReg.h>
shiftReg sr (9, 10, 11, 0); // data pin , clock pin, latch pin, MSB (1) or LSB (0)
void setup () {
;
}
void loop () {
sr.shiftData (0b10101010); // Set an output
delay (1);
sr.allOne (); // Set all output pins to 1
delay (1);
sr.allZero (); // Set all output pins to 0
delay (1);
uint8_t shiftRegister_value = sr.readOut (); // Give out data in the shift register
delay (1);
exit (0);
}
| 26.810345
| 88
| 0.724759
|
52ebcfa81838fe80b211ad8e1fa7421db7922267
| 1,105
|
ino
|
Arduino
|
DroneTestCodes/AltitudeTests/BMP280_Altitude/BMP280_Altitude.ino
|
davidoises/DroneSoftware
|
3952e2f0cfba99fee82568e76da0f0f1c37dfe47
|
[
"MIT"
] | 1
|
2020-08-10T11:38:16.000Z
|
2020-08-10T11:38:16.000Z
|
DroneTestCodes/AltitudeTests/BMP280_Altitude/BMP280_Altitude.ino
|
davidoises/DroneSoftware
|
3952e2f0cfba99fee82568e76da0f0f1c37dfe47
|
[
"MIT"
] | null | null | null |
DroneTestCodes/AltitudeTests/BMP280_Altitude/BMP280_Altitude.ino
|
davidoises/DroneSoftware
|
3952e2f0cfba99fee82568e76da0f0f1c37dfe47
|
[
"MIT"
] | null | null | null |
#include <Wire.h>
#include "Adafruit_BMP280.h"
Adafruit_BMP280 bmp; // I2C
//Adafruit_BMP280 bmp(BMP_CS); // hardware SPI
//Adafruit_BMP280 bmp(BMP_CS, BMP_MOSI, BMP_MISO, BMP_SCK);
float initial_pressure = 0;
void setup() {
Serial.begin(500000);
Serial.println(F("BMP280 test"));
if (!bmp.begin(0x76, 0x58)) {
Serial.println(F("Could not find a valid BMP280 sensor, check wiring!"));
while (1);
}
/* Default settings from datasheet. */
bmp.setSampling(Adafruit_BMP280::MODE_NORMAL, /* Operating Mode. */
Adafruit_BMP280::SAMPLING_X1, /* Temp. oversampling */
Adafruit_BMP280::SAMPLING_X4, /* Pressure oversampling */
Adafruit_BMP280::FILTER_X16, /* Filtering. */
Adafruit_BMP280::STANDBY_MS_1); /* Standby time. */
delay(1000);
for(int i = 0; i < 5; i++)
{
initial_pressure += bmp.readPressure()/100.0;
delay(50);
}
initial_pressure /= 5;
}
void loop() {
Serial.println(bmp.readAltitude(initial_pressure)*100.0); /* Adjusted to local forecast! */
delay(50);
}
| 26.95122
| 95
| 0.628959
|
ab537fc6018dc720cd9983daac636dc9f086ea59
| 1,903
|
ino
|
Arduino
|
arduinoSMS/arduinoSMS.ino
|
SandunK/smsAppUsingGSM
|
8a070477c4da70c06e0507fb2473deacc1aaeebc
|
[
"Apache-2.0"
] | null | null | null |
arduinoSMS/arduinoSMS.ino
|
SandunK/smsAppUsingGSM
|
8a070477c4da70c06e0507fb2473deacc1aaeebc
|
[
"Apache-2.0"
] | null | null | null |
arduinoSMS/arduinoSMS.ino
|
SandunK/smsAppUsingGSM
|
8a070477c4da70c06e0507fb2473deacc1aaeebc
|
[
"Apache-2.0"
] | null | null | null |
#include <SoftwareSerial.h>
SoftwareSerial SIM800(3, 2); // TX,RX
String message;
void ShowSerialData()
{
while(SIM800.available()!=0)
Serial.write(SIM800.read());
}
void setup()
{
Serial.begin(9600); // initialize serial communications at 9600 bps
SIM800.begin(9600);
}
void loop(){
String messageGot = readSerial();
String key, stringVal, number;
for (int i = 0; i < messageGot.length(); i++) {
if (messageGot.substring(i, i+1) == ":") {
key = messageGot.substring(0, i);
stringVal = messageGot.substring(i+1);
break;
}
}
if (key == "msg"){
message=stringVal;
Serial.println("Message received");
//Serial.println(stringVal);
} else if (key == "num") {
//numbers[i]=stringVal
String result = sendSMS(stringVal);
//if (result){
//Serial.println("success");
//}
}
//delay(500);
}
String readSerial(){
// serial read section
String readString;
while (Serial.available()) {
delay(90); //delay to allow buffer to fill
if (Serial.available() >0){
char c = Serial.read(); //gets one byte from serial buffer
readString += c; //makes the string readString
}
}
if (readString.length() >0){
//Serial.print("Arduino received: ");
//Serial.println(readString); //see what was received
Serial.flush();
}
return readString;
}
String sendSMS(String num){
SIM800.print("AT+CMGF=1\r"); //Set the module to SMS mode
delay(100);
SIM800.print("AT+CMGS=\"+94"+num+"\"\r"); //Your phone number don't forget to include your country code, example +212123456789"
delay(500);
SIM800.print(message); //This is the text to send to the phone number, don't make it too long or you have to modify the SoftwareSerial buffer
delay(500);
SIM800.print((char)26);// (required according to the datasheet)
return "success";
}
| 22.927711
| 149
| 0.624803
|
ef4983843ab923abe96982dea953f33587152e28
| 4,826
|
ino
|
Arduino
|
ircomm/ircomm.ino
|
dmcomm/irplot
|
23163a5d2fed2445fee4a7b0df59d80260e02489
|
[
"MIT"
] | null | null | null |
ircomm/ircomm.ino
|
dmcomm/irplot
|
23163a5d2fed2445fee4a7b0df59d80260e02489
|
[
"MIT"
] | null | null | null |
ircomm/ircomm.ino
|
dmcomm/irplot
|
23163a5d2fed2445fee4a7b0df59d80260e02489
|
[
"MIT"
] | null | null | null |
/* This file is part of the DMComm project by BladeSabre. License: MIT. */
#include "ircomm.h"
const byte pinIrLed = 11;
const byte pinInputBasic = 16;
const byte pinInputDemod = 9;
const byte pinProbe = 0;
const int32_t replyTimeout = 20000;
const int32_t initialTimeout = 5000000;
const uint16_t logBufferLength = 500;
uint16_t logBuffer[logBufferLength];
uint16_t logSize;
void setup() {
Serial.begin(9600);
digitalWrite(pinIrLed, LOW);
pinMode(pinIrLed, OUTPUT);
pinMode(pinInputBasic, INPUT_PULLUP);
pinMode(pinInputDemod, INPUT_PULLUP);
pinMode(pinProbe, OUTPUT);
}
uint16_t packDur(uint32_t dur) {
if (dur < 0x8000) {
return dur;
} else if (dur < 0x100000) {
return 0x8000 | (dur >> 5);
} else {
return END;
}
}
uint32_t unpackDur(uint16_t packedDur) {
if (packedDur < 0x8000) {
return packedDur;
} else {
return (((uint32_t)(packedDur & 0x7FFF)) << 5);
}
}
void addLogItem(uint16_t item) {
if (logSize < logBufferLength) {
logBuffer[logSize] = item;
logSize ++;
}
}
void delaySincePrev(uint32_t dur) {
static uint32_t prev = 0;
uint32_t curr;
while (true) {
curr = micros();
if (curr - prev >= dur) {
prev = curr;
return;
}
}
}
void outputPulse(uint16_t t) {
digitalWrite(pinIrLed, HIGH);
delaySincePrev(t);
digitalWrite(pinIrLed, LOW);
}
void outputModulated(uint16_t t) {
uint16_t pulses;
if (t > 1500) {
pulses = (t / 64) * 39 / 16;
} else {
pulses = t * 39 / 1024;
}
for (uint16_t pulse = 0; pulse < pulses; pulse ++) {
digitalWrite(pinIrLed, HIGH);
delaySincePrev(13);
digitalWrite(pinIrLed, LOW);
delaySincePrev(13);
}
//TODO could get it more accurate with PWM.
}
int32_t waitLevel(uint8_t pin, uint8_t level, int32_t timeoutMicros) {
int32_t startTime = micros();
int32_t dur = 0;
while (digitalRead(pin) != level && dur < timeoutMicros) {
dur = micros() - startTime;
}
if (dur < timeoutMicros) {
return dur;
} else {
return -1;
}
}
int8_t receivePacket(bool first) {
int32_t t;
uint8_t pin;
if (first) {
t = initialTimeout;
} else {
t = replyTimeout;
}
if (sequenceHandler.isModulated) {
pin = pinInputDemod;
} else {
pin = pinInputBasic;
}
t = waitLevel(pin, LOW, t);
if (t == -1) {
addLogItem(END);
return -1;
}
if (first) {
addLogItem(0);
} else {
addLogItem(packDur(t)); //TODO ?
}
while (true) {
t = waitLevel(pin, HIGH, sequenceHandler.replyDelay);
if (t == -1) {
//it shouldn't stop in the "on" state
addLogItem(END);
return -1;
}
//recording the "on" time
addLogItem(packDur(t));
t = waitLevel(pin, LOW, sequenceHandler.replyDelay);
if (t == -1) {
//finished
return 0;
}
//recording the "off" time
addLogItem(packDur(t));
}
}
void execute() {
uint16_t cursor = 0;
uint16_t item;
bool wasOn = false;
logSize = 0;
if (!sequenceHandler.goFirst) {
if (receivePacket(true) == -1) {
return;
}
}
delaySincePrev(0);
while (true) {
item = sequenceHandler.get(cursor);
if (item == END) {
return;
}
if (item == WAIT) {
digitalWrite(pinProbe, HIGH);
delaySincePrev(5);
digitalWrite(pinProbe, LOW);
wasOn = false;
if (receivePacket(false) == -1) {
return;
}
delaySincePrev(0);
} else {
if (wasOn) {
delaySincePrev(item);
wasOn = false;
} else if (sequenceHandler.isModulated) {
outputModulated(item);
wasOn = true;
} else {
outputPulse(item);
wasOn = true;
}
}
cursor ++;
}
}
void loop() {
int8_t b;
uint16_t cursor;
if (Serial.available()) {
b = Serial.read();
if (b == '\r' || b == '\n') {
//do nothing
} else if (sequenceHandler.load(b) == 0) {
execute();
for (cursor = 0; cursor < logSize; cursor ++) {
if (logBuffer[cursor] == END) {
Serial.print(F("END"));
} else {
Serial.print(unpackDur(logBuffer[cursor]));
}
Serial.write(',');
}
Serial.println();
} else {
sequenceHandler.list(Serial);
}
}
}
| 23.541463
| 74
| 0.51409
|
ab909ecd38e0934284cef56c4100de5b85f4eaaa
| 4,226
|
ino
|
Arduino
|
Circuit_Schematics_&_Arduino/818W_Code_arduino/818W_Code.ino
|
akdhandy/CMSC818W
|
c7bf899f4876e6bb34208654a31bafe3f5d7a07b
|
[
"MIT"
] | null | null | null |
Circuit_Schematics_&_Arduino/818W_Code_arduino/818W_Code.ino
|
akdhandy/CMSC818W
|
c7bf899f4876e6bb34208654a31bafe3f5d7a07b
|
[
"MIT"
] | null | null | null |
Circuit_Schematics_&_Arduino/818W_Code_arduino/818W_Code.ino
|
akdhandy/CMSC818W
|
c7bf899f4876e6bb34208654a31bafe3f5d7a07b
|
[
"MIT"
] | null | null | null |
#include <Wire.h>
#include "Adafruit_SI1145.h"
Adafruit_SI1145 uv = Adafruit_SI1145();
int ledPin_blue = 13; // The LED is connected on pin 13
int ledPin_green = 12; // The LED is connected on pin 13
int ledPin_red = 8; // The LED is connected on pin 13
int ledPin_ir = 7; // The LED is connected on pin 13
int data_points = 20;
int rgb[20]; // variable to stores data
int ir[20]; // variable to stores data
int ultra[20]; // variable to stores data
void setup() {
// put your setup code here, to run once:
// make the LED pin (pin 13) an output pin
pinMode(ledPin_blue, OUTPUT);
pinMode(ledPin_green, OUTPUT);
pinMode(ledPin_red, OUTPUT);
pinMode(ledPin_ir, OUTPUT);
Serial.begin(9600);
uv.begin();
// Serial.println("Adafruit SI1145 test");
// if (! uv.begin())
// {
// Serial.println("Didn't find Si1145");
// while (1);
// }
// Serial.println("OK!");
// put your main code here, to run repeatedly:============>>>
delay(3000);
digitalWrite(ledPin_blue, LOW);
digitalWrite(ledPin_green, LOW);
digitalWrite(ledPin_red, LOW);
digitalWrite(ledPin_ir, LOW);
delay(3000);
// GREEN HERE =====================>>>>>
digitalWrite(ledPin_green, HIGH);
delay(3000);
for(int i = 0; i<data_points; i++)
{
rgb[i]= uv.readVisible();
ir[i] = uv.readIR();
ultra[i] = uv.readUV();
delay(500);
}
delay(3000);
digitalWrite(ledPin_green, LOW);
for(int i = 0; i<data_points; i++)
{
Serial.println("Green");
delay(500);
Serial.println("rgb");
Serial.println(rgb[i]);
Serial.println("IR");
Serial.println(ir[i]);
Serial.println("UV");
Serial.println(ultra[i]);
// delay(500);
}
// Serial.println("End_green");
// BLUE HERE =====================>>>>>
digitalWrite(ledPin_blue, HIGH);
delay(3000);
for(int i = 0; i<data_points; i++)
{
rgb[i]= uv.readVisible();
ir[i] = uv.readIR();
ultra[i] = uv.readUV();
delay(500);
}
delay(3000);
digitalWrite(ledPin_blue, LOW);
for(int i = 0; i<data_points; i++)
{
Serial.println("Blue");
delay(500);
Serial.println("rgb");
Serial.println(rgb[i]);
Serial.println("IR");
Serial.println(ir[i]);
Serial.println("UV");
Serial.println(ultra[i]);
// delay(500);
}
// Serial.println("End_blue");
// RED HERE =====================>>>>>
digitalWrite(ledPin_red, HIGH);
delay(3000);
for(int i = 0; i<data_points; i++)
{
rgb[i]= uv.readVisible();
ir[i] = uv.readIR();
ultra[i] = uv.readUV();
delay(500);
}
delay(3000);
digitalWrite(ledPin_red, LOW);
for(int i = 0; i<data_points; i++)
{
Serial.println("Red");
delay(500);
Serial.println("rgb");
Serial.println(rgb[i]);
Serial.println("IR");
Serial.println(ir[i]);
Serial.println("UV");
Serial.println(ultra[i]);
// delay(500);
}
// Serial.println("End_red");
// IR HERE =====================>>>>>
digitalWrite(ledPin_ir, HIGH);
delay(3000);
for(int i = 0; i<data_points; i++)
{
rgb[i]= uv.readVisible();
ir[i] = uv.readIR();
ultra[i] = uv.readUV();
delay(500);
}
delay(3000);
digitalWrite(ledPin_ir, LOW);
for(int i = 0; i<data_points; i++)
{
Serial.println("Infrared");
delay(500);
Serial.println("rgb");
Serial.println(rgb[i]);
Serial.println("IR");
Serial.println(ir[i]);
Serial.println("UV");
Serial.println(ultra[i]);
// delay(500);
}
// Serial.println("End_ir");
delay(3000);
Serial.println("End");
// Serial.println("===================");
// Serial.print("Vis: "); Serial.println(uv.readVisible());
// Serial.print("IR: "); Serial.println(uv.readIR());
//
// // Uncomment if you have an IR LED attached to LED pin!
//// Serial.print("Prox: "); Serial.println(uv.readProx());
//
// float UVindex = uv.readUV();
// // the index is multiplied by 100 so to get the
// // integer index, divide by 100!
// UVindex /= 100.0;
// Serial.print("UV: "); Serial.println(UVindex);
//
// delay(5000);
// digitalWrite(ledPin_blue, LOW);
// digitalWrite(ledPin_green, HIGH);
// delay(5000);
}
void loop()
{}
| 20.614634
| 65
| 0.575248
|
0a9c7cf25c807bcc5e33819a7f024d7e93853b50
| 2,995
|
ino
|
Arduino
|
김병갑/라즈베리파이/아두이노 연동/웹까지 연동/ArduRasp/ArduRasp.ino
|
Fishberry/RemoteFishbowl
|
a8b0d987efc6be135358029f5b45f2d3425d92f1
|
[
"MIT"
] | 6
|
2019-01-03T05:47:34.000Z
|
2020-11-21T00:57:06.000Z
|
김병갑/라즈베리파이/아두이노 연동/웹까지 연동/ArduRasp/ArduRasp.ino
|
Fishberry/RemoteFishbowl
|
a8b0d987efc6be135358029f5b45f2d3425d92f1
|
[
"MIT"
] | null | null | null |
김병갑/라즈베리파이/아두이노 연동/웹까지 연동/ArduRasp/ArduRasp.ino
|
Fishberry/RemoteFishbowl
|
a8b0d987efc6be135358029f5b45f2d3425d92f1
|
[
"MIT"
] | 1
|
2019-01-06T09:40:35.000Z
|
2019-01-06T09:40:35.000Z
|
#include <OneWire.h>
#include <Servo.h>
#include <Wire.h>
#include "RTClib.h"
const int DS18S20_Pin = 2;
const int WaterPumpA1 = 6;
const int WaterPumpA2 = 7;
const int WaterPumpB1 = 4;
const int WaterPumpB2 = 5;
const int SERVO = 8;
Servo myServo;
RTC_DS1307 RTC;
String year, month, day, hour, minute, second, time, date;
OneWire ds(DS18S20_Pin);
void setup()
{
Serial.begin(9600);
myServo.attach(SERVO);
Wire.begin();
RTC.begin();
if(!RTC.isrunning())
{
RTC.adjust(DateTime(__DATE__, __TIME__));
}
pinMode(WaterPumpA1, OUTPUT);
pinMode(WaterPumpA2, OUTPUT);
pinMode(WaterPumpB1, OUTPUT);
pinMode(WaterPumpB2, OUTPUT);
}
void loop()
{
String userHour = "14";
String userMinute = "8";
if(Serial.available())
{
char c = Serial.read();
if(c == '1')
{
getTemp();
}
if(c == '2')
{
operateServo();
}
if(c == '3')
{
operateMotor();
}
c = '4';
}
}
boolean getTime(String userHour, String userMinute)
{
DateTime now = RTC.now();
Serial.print(now.year(), DEC);
year = String(now.year(), DEC);
Serial.print('/');
Serial.print(now.month(), DEC);
month = String(now.month(), DEC);
Serial.print('/');
Serial.print(now.day(), DEC);
day = String(now.day(), DEC);
Serial.print('/');
Serial.print(now.hour(), DEC);
hour = String(now.hour(), DEC);
Serial.print('/');
Serial.print(now.minute(), DEC);
minute = String(now.minute(), DEC);
Serial.print('/');
Serial.print(now.second(), DEC);
second = String(now.second(), DEC);
Serial.print(' ');
Serial.println();
delay(1000);
if(hour == userHour && minute == userMinute)
{
return true;
}
else
{
return false;
}
}
float getTemp()
{
byte data[12];
byte addr[8];
if(!ds.search(addr))
{
Serial.println("no more sensors on chain, reset search!");
ds.reset_search();
return -1000;
}
if(OneWire::crc8(addr, 7) != addr[7])
{
Serial.println("CRC is not vaild!");
return -1000;
}
if(addr[0] != 0x10 && addr[0] != 0x28)
{
Serial.print("Device is not recognized");
return -1000;
}
ds.reset();
ds.select(addr);
ds.write(0x44, 1);
byte present = ds.reset();
ds.select(addr);
ds.write(0xBE);
for(int i = 0; i < 9; i++)
{
data[i] = ds.read();
}
ds.reset_search();
byte MSB = data[1];
byte LSB = data[0];
float tempRead = ((MSB << 8) | LSB);
float Temper = tempRead / 16;
return Temper;
}
void operateMotor()
{
analogWrite(WaterPumpA1, 255);
analogWrite(WaterPumpA2, 0);
delay(1000);
analogWrite(WaterPumpA1, 0);
analogWrite(WaterPumpA2, 0);
delay(3000);
analogWrite(WaterPumpB1, 255);
analogWrite(WaterPumpB2, 0);
delay(1000);
analogWrite(WaterPumpB1, 0);
analogWrite(WaterPumpB2, 0);
delay(3000);
}
void operateServo()
{
for(int i = 0; i < 180; i++)
{
myServo.write(i);
delay(15);
}
myServo.write(0);
delay(1000);
}
| 17.114286
| 62
| 0.589983
|
8658a8984a2975373f97733c416d6f78fd925fe6
| 3,218
|
ino
|
Arduino
|
RunStop/RunStopRelay/RunStopRelay.ino
|
HankelBao/scale-vehicle-control-stack
|
d71c30a62b81693fc35ea2fda4fe6954f1d9dd78
|
[
"MIT"
] | null | null | null |
RunStop/RunStopRelay/RunStopRelay.ino
|
HankelBao/scale-vehicle-control-stack
|
d71c30a62b81693fc35ea2fda4fe6954f1d9dd78
|
[
"MIT"
] | null | null | null |
RunStop/RunStopRelay/RunStopRelay.ino
|
HankelBao/scale-vehicle-control-stack
|
d71c30a62b81693fc35ea2fda4fe6954f1d9dd78
|
[
"MIT"
] | null | null | null |
/**
* TODO:
* 1. Emergency stop if/when a client becomes disconnected
* 2. Create LED system that actually indicates connection or meaning
*/
#include "Constants.h"
#include "LED.h"
#include "Switch.h"
#include <ArduinoOTA.h>
#include <ESP8266WiFi.h>
LED statusLED(LED_STATUS_PIN);
Switch powerSwitch(POWER_SWITCH_PIN);
Switch steeringSwitch(STEERING_SWITCH_PIN);
Switch motorSwitch(MOTOR_SWITCH_PIN);
const char *ssid = "AutonomousRC"; // SSID
const char *pass = "AutonomousRC"; // password
IPAddress ip(192, 168, 0, 80); // IP address of the server
IPAddress gateway(192, 168, 0, 1); // gateway of your network
IPAddress mask(255, 255, 255, 0); // subnet mask of your network
WiFiServer server(80);
// A name and a password for the OTA service
const char *OTAName = "AutonomousRC";
const char *OTAPassword = "";
enum Command { POWER, AUTO };
struct Message {
Command command;
};
void setup() {
Serial.begin(BAUD_RATE);
startWiFi();
startServer();
startOTA();
}
void loop() {
// if (!server.hasClient()) emergencyStop();
WiFiClient client = server.available();
if (!client)
return;
while (!client.available()) {
}
Message message;
byte *messageBuffer = (byte *)&message;
while (client.available()) {
messageBuffer += client.read(messageBuffer, 1);
}
Serial.print("Message Command Received :: ");
Serial.println(message.command);
handleMessage(message);
statusLED.blink();
}
// void emergencyStop() {
// Serial.println("EMERGENCY STOP");
// powerSwitch.off();
// steeringSwitch.off();
// motorSwitch.off();
//}
/**
Start a Wi-Fi access point. Wait for the AP connection.
*/
void startWiFi() {
WiFi.mode(WIFI_AP);
WiFi.softAP(ssid, pass); // Start the access point
WiFi.softAPConfig(ip, gateway, mask);
Serial.print("Access Point \"");
Serial.print(ssid);
Serial.println("\" started\r\n");
statusLED.blink();
}
/**
State the WiFi Server
*/
void startServer() { server.begin(); }
/**
Start the OTA service
*/
void startOTA() {
ArduinoOTA.setHostname(OTAName);
ArduinoOTA.setPassword(OTAPassword);
ArduinoOTA.onStart([]() { Serial.println("Start"); });
ArduinoOTA.onEnd([]() { Serial.println("\r\nEnd"); });
ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) {
Serial.printf("Progress: %u%%\r", (progress / (total / 100)));
});
ArduinoOTA.onError([](ota_error_t error) {
Serial.printf("Error[%u]: ", error);
if (error == OTA_AUTH_ERROR)
Serial.println("Auth Failed");
else if (error == OTA_BEGIN_ERROR)
Serial.println("Begin Failed");
else if (error == OTA_CONNECT_ERROR)
Serial.println("Connect Failed");
else if (error == OTA_RECEIVE_ERROR)
Serial.println("Receive Failed");
else if (error == OTA_END_ERROR)
Serial.println("End Failed");
});
ArduinoOTA.begin();
Serial.println("OTA ready\r\n");
}
void handleMessage(const Message &message) {
Serial.println("Received Message");
switch (message.command) {
case POWER:
Serial.println("Flipping Power Switch");
powerSwitch.flip();
break;
case AUTO:
Serial.println("Flipping Auto Switch");
steeringSwitch.flip();
motorSwitch.flip();
break;
}
}
| 24.753846
| 71
| 0.672467
|
4d72f8a777abbebc8ece8cf4402ad472ef0c8f60
| 2,580
|
ino
|
Arduino
|
gate.ino
|
iruz17/smart-tourism-device
|
df08a3157feb4e34a7a870df96c4dc02fb652295
|
[
"MIT"
] | 1
|
2021-02-15T13:43:25.000Z
|
2021-02-15T13:43:25.000Z
|
gate.ino
|
threeal/smart-tourism-device
|
df08a3157feb4e34a7a870df96c4dc02fb652295
|
[
"MIT"
] | null | null | null |
gate.ino
|
threeal/smart-tourism-device
|
df08a3157feb4e34a7a870df96c4dc02fb652295
|
[
"MIT"
] | 1
|
2021-02-14T04:16:45.000Z
|
2021-02-14T04:16:45.000Z
|
#include <LiquidCrystal_PCF8574.h>
#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
#include <SPI.h>
#include <MFRC522.h>
#define RST_PIN D3
#define SDA_PIN D4
// Change this according to the WiFi SSID and password
String wifi_ssid = "SSID";
String wifi_pass = "password";
// Change this according to the server address
String server_address = "http://192.168.1.1:8080";
// Change this according to the gate id
String gate_id = "5ff98afe90384e440c3d6bec";
LiquidCrystal_PCF8574 lcd(0x3F);
MFRC522 mfrc522(SDA_PIN, RST_PIN);
void lcdPrint(String a, String b) {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(a);
lcd.setCursor(0, 1);
lcd.print(b);
Serial.println(a + " " + b);
}
void setup() {
Serial.begin(9600);
lcd.begin(16, 2);
lcdPrint("Inisialisasi", "perangkat");
delay(2000);
SPI.begin();
mfrc522.PCD_Init();
}
void loop() {
if (WiFi.status() != WL_CONNECTED) {
lcdPrint("Menghubungkan ke", wifi_ssid);
WiFi.begin(wifi_ssid, wifi_pass);
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
}
lcdPrint("Terhubung ke", "WiFi");
delay(2000);
lcdPrint("Alamat IP", WiFi.localIP().toString());
delay(2000);
lcdPrint("Mengubungkan ke", server_address);
HTTPClient http;
http.begin(server_address);
int http_rc = http.GET();
while (http_rc <= 0) {
http_rc = http.GET();
delay(1000);
}
http.end();
lcdPrint("Terhubung ke", "server");
delay(2000);
lcdPrint("Silahkan tempel", "kartu");
delay(2000);
}
if (!mfrc522.PICC_IsNewCardPresent()) {
return;
}
if (!mfrc522.PICC_ReadCardSerial()) {
return;
}
String tag_id = "";
for(byte i = 0; i < mfrc522.uid.size; i++){
tag_id.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? "0" : ""));
tag_id.concat(String(mfrc522.uid.uidByte[i], HEX));
}
tag_id.toUpperCase();
lcdPrint("Kartu terdeteksi:", tag_id);
delay(2000);
lcdPrint("Memverifikasi", "kartu");
HTTPClient http;
String api_address = server_address + "/api/device/visitation/";
http.begin(api_address + gate_id + "/" + tag_id);
int http_rc = http.POST("");
if (http_rc >= 0) {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(http.getString());
Serial.println(http.getString());
delay(2000);
}
else {
lcdPrint("Kesalahan perangkat", "");
delay(2000);
}
http.end();
lcdPrint("Silahkan tempel", "kartu");
delay(2000);
}
| 20.47619
| 69
| 0.604651
|
37f61cc64136be0ef90c60187047b7f9034dc183
| 2,261
|
ino
|
Arduino
|
A18 Stepper28BYJ-48/Stepper_Servo_V1/Stepper_Servo_V1.ino
|
frankyhub/Arduin---Beispiele-I
|
78c86561b4401266414acdb91a911e55c9037755
|
[
"MIT"
] | 1
|
2021-09-24T22:21:46.000Z
|
2021-09-24T22:21:46.000Z
|
Servo-Stepper/Servo-Stepper.ino
|
frankyhub/BotArm_MK3
|
baf5c13ac96c2236def461c02656d35a25416207
|
[
"MIT"
] | null | null | null |
Servo-Stepper/Servo-Stepper.ino
|
frankyhub/BotArm_MK3
|
baf5c13ac96c2236def461c02656d35a25416207
|
[
"MIT"
] | null | null | null |
/* Board NANO
* ATmegam328Pm(Old Bootloader
*
* Stepper für MK3
* Serieller Monitor > Joy-Poti
* INT LED HIGH bei Mittelstellung
*
*
* KHF 07.11.2020 Servo eingefügt
* KHF 06.11. 2020 Stillstand optimiert re/li
*
* Stepper
* joystick A0
* IN4, IN2, IN3, IN1
* PIN 11 10 9 8
*
* Servo
* Poti1 = A4
* PWM PIN 6
*
* Ver 17.11.2020
* KHF
*/
#include <Stepper.h>
#define STEPS 32
// Stepper Anschlüsse
#define IN1 8
#define IN2 10
#define IN3 9
#define IN4 11
// Library initialisieren
Stepper stepper(STEPS, IN4, IN2, IN3, IN1);
//PINS NANO 11 10 9 8
// Joystick/Poti an NANO A0
#define joystick A0
int LED13 = 13; // Interne LED
//----------Servo--------------------
#include <Servo.h>
Servo Motor;
int ReglerWert;
int Position;
//-----------------------------------
void setup()
{
Serial.begin(9600);
//Gr_servo.attach(6); //PWM#6
int Poti1 = analogRead(A4);
// Servo an Pin 6 angeschlossen (attach)
Motor.attach(6);
}
void loop()
{
// Analogwert einlesen
int val = analogRead(joystick);
Serial.print(val);
Serial.println();
// Wenn Joystick in Mittelstellung = Motor stopp
if( (val > 523) && (val < 500) )
{
digitalWrite(IN1, LOW);
digitalWrite(IN2, LOW);
digitalWrite(IN3, LOW);
digitalWrite(IN4, LOW);
digitalWrite(LED13, HIGH);
}
else
{
// Motor rechts
//while (val >= 523)
while (val >= 723)
{
digitalWrite(LED13, LOW);
// map Speed zwischen 0 und 500 rpm
int speed_ = map(val, 723, 1023, 5, 500);
// Motor Speed
stepper.setSpeed(speed_);
// Motordrehung = 1 Stepp
stepper.step(1);
val = analogRead(joystick);
Serial.print(val);
Serial.println();
}
// Motor links
while (val <= 300)
{
digitalWrite(LED13, LOW);
// Speed zwischen 0 und 500 rpm
int speed_ = map(val, 500, 0, 5, 300);
// Set Motor Speed
stepper.setSpeed(speed_);
// Motordrehung = 1 Stepp
stepper.step(-1);
val = analogRead(joystick);
//Serial.print(val);
//Serial.println();
}
}
//Greifarm
int ReglerWert = analogRead(A4);
Position = map(ReglerWert, 0, 1023, 0, 180);
Motor.write(Position);
delay(100);
}
| 18.233871
| 49
| 0.584255
|
d36f81146f9fa10d7079fea61e44186eb3057afd
| 6,172
|
ino
|
Arduino
|
examples/Serial_EMG/Serial_EMG.ino
|
ferdinandkeil/ADS129X
|
e4bd32c5feec9d23b34b92f015dbf176bbbeafe5
|
[
"MIT"
] | 18
|
2015-10-12T01:08:49.000Z
|
2021-11-24T01:31:02.000Z
|
examples/Serial_EMG/Serial_EMG.ino
|
rlong19/ADS129X
|
cefb18b8dd7da5223d15c5497a70221fb1d9e40d
|
[
"MIT"
] | 2
|
2016-09-14T12:41:01.000Z
|
2018-05-08T19:09:51.000Z
|
examples/Serial_EMG/Serial_EMG.ino
|
ferdinandkeil/ADS129X
|
e4bd32c5feec9d23b34b92f015dbf176bbbeafe5
|
[
"MIT"
] | 8
|
2016-05-13T05:51:27.000Z
|
2022-02-11T04:22:39.000Z
|
#include <ADS129X.h>
#include <SPI.h>
/* ADS129X pins */
const int PSU_NEG = 1;
const int PSU_POS = 0;
const int ADS_PWDN = 2;
const int ADS_RESET = 3;
const int ADS_START = 4;
const int ADS_DRDY = 5;
const int ADS_CS = 10;
/* LEDs */
const int LED1 = 16;
const int LED2 = 17;
const int LED3 = 18;
/* Button */
const int BUTTON = 15;
/* nRF8001 pins */
const int NRF_RST = 7;
int fourbfiveb[] = {
0b11110, // Hex data 0
0b01001, // Hex data 1
0b10100, // Hex data 2
0b10101, // Hex data 3
0b01010, // Hex data 4
0b01011, // Hex data 5
0b01110, // Hex data 6
0b01111, // Hex data 7
0b10010, // Hex data 8
0b10011, // Hex data 9
0b10110, // Hex data A
0b10111, // Hex data B
0b11010, // Hex data C
0b11011, // Hex data D
0b11100, // Hex data E
0b11101 // Hex data F
};
#define encode4B5B(x) (fourbfiveb[x&0x0F])
#define HIGH_NIBBLE(x) (x>>4)
#define LOW_NIBBLE(x) (x&0x0F)
/*uint32_t fourbfiveb[256] = {
0x1e1e, 0x1e09, 0x1e14, 0x1e15, 0x1e0a, 0x1e0b, 0x1e0e, 0x1e0f,
0x1e12, 0x1e13, 0x1e16, 0x1e17, 0x1e1a, 0x1e1b, 0x1e1c, 0x1e1d,
0x091e, 0x0909, 0x0914, 0x0915, 0x090a, 0x090b, 0x090e, 0x090f,
0x0912, 0x0913, 0x0916, 0x0917, 0x091a, 0x091b, 0x091c, 0x091d,
0x141e, 0x1409, 0x1414, 0x1415, 0x140a, 0x140b, 0x140e, 0x140f,
0x1412, 0x1413, 0x1416, 0x1417, 0x141a, 0x141b, 0x141c, 0x141d,
0x151e, 0x1509, 0x1514, 0x1515, 0x150a, 0x150b, 0x150e, 0x150f,
0x1512, 0x1513, 0x1516, 0x1517, 0x151a, 0x151b, 0x151c, 0x151d,
0x0a1e, 0x0a09, 0x0a14, 0x0a15, 0x0a0a, 0x0a0b, 0x0a0e, 0x0a0f,
0x0a12, 0x0a13, 0x0a16, 0x0a17, 0x0a1a, 0x0a1b, 0x0a1c, 0x0a1d,
0x0b1e, 0x0b09, 0x0b14, 0x0b15, 0x0b0a, 0x0b0b, 0x0b0e, 0x0b0f,
0x0b12, 0x0b13, 0x0b16, 0x0b17, 0x0b1a, 0x0b1b, 0x0b1c, 0x0b1d,
0x0e1e, 0x0e09, 0x0e14, 0x0e15, 0x0e0a, 0x0e0b, 0x0e0e, 0x0e0f,
0x0e12, 0x0e13, 0x0e16, 0x0e17, 0x0e1a, 0x0e1b, 0x0e1c, 0x0e1d,
0x0f1e, 0x0f09, 0x0f14, 0x0f15, 0x0f0a, 0x0f0b, 0x0f0e, 0x0f0f,
0x0f12, 0x0f13, 0x0f16, 0x0f17, 0x0f1a, 0x0f1b, 0x0f1c, 0x0f1d,
0x121e, 0x1209, 0x1214, 0x1215, 0x120a, 0x120b, 0x120e, 0x120f,
0x1212, 0x1213, 0x1216, 0x1217, 0x121a, 0x121b, 0x121c, 0x121d,
0x131e, 0x1309, 0x1314, 0x1315, 0x130a, 0x130b, 0x130e, 0x130f,
0x1312, 0x1313, 0x1316, 0x1317, 0x131a, 0x131b, 0x131c, 0x131d,
0x161e, 0x1609, 0x1614, 0x1615, 0x160a, 0x160b, 0x160e, 0x160f,
0x1612, 0x1613, 0x1616, 0x1617, 0x161a, 0x161b, 0x161c, 0x161d,
0x171e, 0x1709, 0x1714, 0x1715, 0x170a, 0x170b, 0x170e, 0x170f,
0x1712, 0x1713, 0x1716, 0x1717, 0x171a, 0x171b, 0x171c, 0x171d,
0x1a1e, 0x1a09, 0x1a14, 0x1a15, 0x1a0a, 0x1a0b, 0x1a0e, 0x1a0f,
0x1a12, 0x1a13, 0x1a16, 0x1a17, 0x1a1a, 0x1a1b, 0x1a1c, 0x1a1d,
0x1b1e, 0x1b09, 0x1b14, 0x1b15, 0x1b0a, 0x1b0b, 0x1b0e, 0x1b0f,
0x1b12, 0x1b13, 0x1b16, 0x1b17, 0x1b1a, 0x1b1b, 0x1b1c, 0x1b1d,
0x1c1e, 0x1c09, 0x1c14, 0x1c15, 0x1c0a, 0x1c0b, 0x1c0e, 0x1c0f,
0x1c12, 0x1c13, 0x1c16, 0x1c17, 0x1c1a, 0x1c1b, 0x1c1c, 0x1c1d,
0x1d1e, 0x1d09, 0x1d14, 0x1d15, 0x1d0a, 0x1d0b, 0x1d0e, 0x1d0f,
0x1d12, 0x1d13, 0x1d16, 0x1d17, 0x1d1a, 0x1d1b, 0x1d1c, 0x1d1d
};*/
//#define encode4B5B(x) (fourbfiveb[x&0xFF])
ADS129X ADS = ADS129X(ADS_DRDY, ADS_CS);
void setup() {
pinMode(PSU_NEG, OUTPUT);
pinMode(PSU_POS, OUTPUT);
pinMode(ADS_RESET, OUTPUT);
pinMode(ADS_PWDN, OUTPUT);
pinMode(ADS_START, OUTPUT);
pinMode(LED1, OUTPUT);
pinMode(LED2, OUTPUT);
pinMode(LED3, OUTPUT);
pinMode(BUTTON, INPUT);
pinMode(NRF_RST, OUTPUT);
digitalWrite(NRF_RST, LOW);
digitalWrite(LED1, HIGH);
digitalWrite(PSU_POS, HIGH);
digitalWrite(PSU_NEG, HIGH);
delay(100); // wait for PSUs to come UP
digitalWrite(ADS_START, LOW);
digitalWrite(ADS_PWDN, HIGH); // turn off power down mode
digitalWrite(ADS_RESET, HIGH);
delay(100); // delay for power-on-reset (Datasheet, pg. 48)
// reset pulse
digitalWrite(ADS_RESET, LOW);
digitalWrite(ADS_RESET, HIGH);
delay(1); // Wait for 18 tCLKs AKA 9 microseconds, we use 1 millisec
ADS.SDATAC(); // device wakes up in RDATAC mode, so send stop signal
ADS.WREG(ADS129X_REG_CONFIG1, ADS129X_SAMPLERATE_32); // enable 8kHz sample-rate
ADS.WREG(ADS129X_REG_CONFIG3, (1<<ADS129X_BIT_PD_REFBUF) | (1<<6)); // enable internal reference
//ADS.WREG(ADS129X_REG_CONFIG2, (1<<ADS129X_BIT_INT_TEST) | ADS129X_TEST_FREQ_2HZ);
// setup channels
ADS.configChannel(1, false, ADS129X_GAIN_12X, ADS129X_MUX_NORMAL);
ADS.configChannel(2, false, ADS129X_GAIN_12X, ADS129X_MUX_NORMAL);
for (int i = 3; i <= 8; i++) {
ADS.configChannel(i, false, ADS129X_GAIN_1X, ADS129X_MUX_SHORT);
}
delay(1);
ADS.RDATAC();
ADS.START();
Serial.begin(0); // always at 12Mbit/s
digitalWrite(LED2, HIGH);
digitalWrite(LED3, HIGH);
}
void loop() {
long buffer[9];
static unsigned long tLast;
if (millis()-tLast > 500) {
digitalWrite(LED3, !digitalRead(LED3));
tLast = millis();
}
if (ADS.getData(buffer)) {
unsigned long tStart = micros();
for (int channel = 1; channel < 9; channel++) {
/*if (channel == 8) {
buffer[channel] = micros()-tStart;
}*/
byte value[3];
byte packet[5];
byte encoded[7];
// convert long to bytes
value[0] = (byte) (buffer[channel]>>16);
value[1] = (byte) (buffer[channel]>>8);
value[2] = (byte) (buffer[channel]);
// encode bytes with 4b5b
encoded[0] = encode4B5B( LOW_NIBBLE(channel));
encoded[1] = encode4B5B(HIGH_NIBBLE(value[0]));
encoded[2] = encode4B5B( LOW_NIBBLE(value[0]));
encoded[3] = encode4B5B(HIGH_NIBBLE(value[1]));
encoded[4] = encode4B5B( LOW_NIBBLE(value[1]));
encoded[5] = encode4B5B(HIGH_NIBBLE(value[2]));
encoded[6] = encode4B5B( LOW_NIBBLE(value[2]));
/*
assemble packet
format:
---- -000 | 0011 1112 | 2222 3333 | 3444 4455 | 5556 6666
dashes are zeros
*/
packet[0] = 0 | (encoded[0]>>2);
packet[1] = (encoded[0]<<6) | (encoded[1]<<1) | (encoded[2]>>4);
packet[2] = (encoded[2]<<4) | (encoded[3]>>1);
packet[3] = (encoded[3]<<7) | (encoded[4]<<2) | (encoded[5]>>3);
packet[4] = (encoded[5]<<5) | (encoded[6]);
// send packet
Serial.write(packet, 5);
}
}
}
| 34.480447
| 98
| 0.667045
|
5d90db05ecb03905666eb549b69d351e7d0f988d
| 7,501
|
ino
|
Arduino
|
src/src/rx5808-pro-diversity.ino
|
JyeSmith/rx5808-pro-diversity
|
7d29ef47afccbe674dac49744b397f5c1c913757
|
[
"MIT"
] | 63
|
2018-09-05T11:57:29.000Z
|
2022-02-18T06:59:41.000Z
|
src/src/rx5808-pro-diversity.ino
|
JyeSmith/rx5808-pro-diversity
|
7d29ef47afccbe674dac49744b397f5c1c913757
|
[
"MIT"
] | 2
|
2022-01-04T22:28:27.000Z
|
2022-03-20T03:46:40.000Z
|
src/src/rx5808-pro-diversity.ino
|
JyeSmith/rx5808-pro-diversity
|
7d29ef47afccbe674dac49744b397f5c1c913757
|
[
"MIT"
] | 5
|
2018-11-06T00:56:32.000Z
|
2021-01-24T13:00:48.000Z
|
/*
SPI driver based on fs_skyrf_58g-main.c Written by Simon Chambers
TVOUT by Myles Metzel
Scanner by Johan Hermen
Inital 2 Button version by Peter (pete1990)
Refactored and GUI reworked by Marko Hoepken
Universal version my Marko Hoepken
Diversity Receiver Mode and GUI improvements by Shea Ivey
OLED Version by Shea Ivey
Seperating display concerns by Shea Ivey
The MIT License (MIT)
Copyright (c) 2015 Marko Hoepken
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), bto deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include <EEPROM.h>
#include "settings.h"
#include "settings_eeprom.h"
#include "state_home.h"
#include "channels.h"
#include "receiver.h"
#include "receiver_spi.h"
#include "state.h"
#include "ui.h"
#include "voltage.h"
#include "temperature.h"
#include "touchpad.h"
#include "receiver_spi.h"
#include <esp_now.h>
#include <WiFi.h>
#include "ExpressLRS_Protocol.h"
#include "WebUpdater.h"
#ifdef SPEED_TEST
uint32_t n = 0;
uint32_t previousTime = millis();
#endif
/*
esp-now setup for communicating to https://github.com/AlessandroAU/ExpressLRS
broadcastAddress is the mac of your receiving esp8266
*/
uint8_t broadcastAddress[] = {0x50, 0x02, 0x91, 0xDA, 0x56, 0xCA, // esp32 tx 50:02:91:DA:56:CA
0x50, 0x02, 0x91, 0xDA, 0x37, 0x84}; // r9 tx 50:02:91:DA:37:84
bool updatingOTA = false;
uint32_t previousLEDTime = 0;
void setup()
{
#ifdef SPEED_TEST
Serial.begin(115200);
#endif
EEPROM.begin(2048);
SPI.begin();
EepromSettings.setup();
setupPins();
StateMachine::setup();
Ui::setup();
TouchPad::setup();
// Has to be last setup() otherwise channel may not be set.
// RX possibly not booting quick enough if setup() is called earler.
// delay() may be needed.
Receiver::setup();
if (!EepromSettings.isCalibrated) {
StateMachine::switchState(StateMachine::State::SETTINGS_RSSI);
Ui::tvOn();
} else {
StateMachine::switchState(StateMachine::State::HOME);
}
if (EepromSettings.otaUpdateRequested)
{
BeginWebUpdate();
EepromSettings.otaUpdateRequested = false;
EepromSettings.save();
updatingOTA = true;
} else
/*
esp-now setup for communicating to https://github.com/AlessandroAU/ExpressLRS
*/
{
WiFi.mode(WIFI_STA);
if (esp_now_init() != ESP_OK) {
// Serial.println("Error initializing ESP-NOW");
return;
}
// Adds broadcastAddress
esp_now_peer_info_t injectorInfo;
for (int i = 0; i < sizeof(broadcastAddress) / 6; i++)
{
memcpy(injectorInfo.peer_addr, broadcastAddress + (6 * i), 6);
injectorInfo.channel = 0;
injectorInfo.encrypt = false;
if (esp_now_add_peer(&injectorInfo) != ESP_OK){
// Serial.println("Failed to add peer");
return;
}
}
}
}
void setupPins() {
// Rx and Tx set as input so that they are high impedance when conencted to goggles.
pinMode(1, INPUT);
pinMode(3, INPUT);
pinMode(PIN_SPI_SLAVE_SELECT_RX_A, OUTPUT);
digitalWrite(PIN_SPI_SLAVE_SELECT_RX_A, HIGH);
pinMode(PIN_SPI_SLAVE_SELECT_RX_B, OUTPUT);
digitalWrite(PIN_SPI_SLAVE_SELECT_RX_B, HIGH);
pinMode(PIN_TOUCHPAD_SLAVE_SELECT, OUTPUT);
digitalWrite(PIN_TOUCHPAD_SLAVE_SELECT, HIGH);
pinMode(PIN_RX_SWITCH, OUTPUT);
digitalWrite(PIN_RX_SWITCH, LOW);
pinMode(PIN_TOUCHPAD_DATA_READY, INPUT);
pinMode(PIN_RSSI_A, INPUT);
pinMode(PIN_RSSI_B, INPUT);
// pinMode(PIN_RSSI_C, INPUT);
// pinMode(PIN_RSSI_D, INPUT);
analogSetPinAttenuation(PIN_VBAT, ADC_2_5db);
}
void loop() {
if (updatingOTA)
{
HandleWebUpdate();
if (millis() > previousLEDTime+100)
{
digitalWrite(PIN_RX_SWITCH, !digitalRead(PIN_RX_SWITCH));
previousLEDTime = millis();
}
} else
{
Receiver::update();
TouchPad::update();
if (Ui::isTvOn) {
#ifdef USE_VOLTAGE_MONITORING
Voltage::update();
#endif
Ui::display.begin(0);
StateMachine::update();
Ui::update();
Ui::display.end();
EepromSettings.update();
}
if (TouchPad::touchData.isActive) {
Ui::UiTimeOut.reset();
}
if (Ui::isTvOn &&
Ui::UiTimeOut.hasTicked() &&
StateMachine::currentState != StateMachine::State::SETTINGS_RSSI )
{
Ui::tvOff();
EepromSettings.update();
}
if (!Ui::isTvOn &&
TouchPad::touchData.buttonPrimary)
{
TouchPad::touchData.buttonPrimary = false;
Ui::tvOn();
}
TouchPad::clearTouchData();
#ifdef SPEED_TEST
n++;
uint32_t nowTime = millis();
if (nowTime > previousTime + 1000) {
Serial.print(n);
Serial.println(" Hz");
previousTime = nowTime;
n = 0;
}
#endif
}
}
uint8_t crc8_dvb_s2(uint8_t crc, unsigned char a)
{
crc ^= a;
for (int ii = 0; ii < 8; ++ii) {
if (crc & 0x80) {
crc = (crc << 1) ^ 0xD5;
} else {
crc = crc << 1;
}
}
return crc;
}
void sendToExLRS(uint16_t function, uint16_t payloadSize, const uint8_t *payload)
{
uint8_t nowDataOutput[9 + payloadSize] = {0};
nowDataOutput[0] = '$';
nowDataOutput[1] = 'X';
nowDataOutput[2] = '<';
nowDataOutput[3] = '0';
nowDataOutput[4] = function & 0xff;
nowDataOutput[5] = (function >> 8) & 0xff;
nowDataOutput[6] = payloadSize & 0xff;
nowDataOutput[7] = (payloadSize >> 8) & 0xff;
for (int i = 0; i < payloadSize; i++)
{
nowDataOutput[8 + i] = payload[i];
}
uint8_t ck2 = 0;
for(int i = 3; i < payloadSize+8; i++)
{
ck2=crc8_dvb_s2(ck2, nowDataOutput[i]);
}
nowDataOutput[payloadSize+8] = ck2;
for (int i = 0; i < sizeof(broadcastAddress) / 6; i++)
{
uint8_t tempBroadcastAddress[6];
memcpy(tempBroadcastAddress, broadcastAddress + (6 * i), 6);
esp_now_send(tempBroadcastAddress, (uint8_t *) &nowDataOutput, sizeof(nowDataOutput));
}
}
| 27.988806
| 97
| 0.610985
|
19fe953ab834033f8a081429b6ab7747e393c0f7
| 2,780
|
ino
|
Arduino
|
Blink_LED_MQTT_Adafruit/Blink_LED_MQTT_Adafruit.ino
|
UBSHARON93/NodeMCU
|
65dc5f96b72e2ac5be02e3fb2218e11acd8e6c8b
|
[
"MIT"
] | null | null | null |
Blink_LED_MQTT_Adafruit/Blink_LED_MQTT_Adafruit.ino
|
UBSHARON93/NodeMCU
|
65dc5f96b72e2ac5be02e3fb2218e11acd8e6c8b
|
[
"MIT"
] | null | null | null |
Blink_LED_MQTT_Adafruit/Blink_LED_MQTT_Adafruit.ino
|
UBSHARON93/NodeMCU
|
65dc5f96b72e2ac5be02e3fb2218e11acd8e6c8b
|
[
"MIT"
] | null | null | null |
#include <ESP8266WiFi.h>
#include "Adafruit_MQTT.h"
#include "Adafruit_MQTT_Client.h"
#define WIFI_SSID "TP-LINK_3EAE"
#define WIFI_PASS "49836318"
#define MQTT_SERV "io.adafruit.com"
#define MQTT_PORT 1883
#define MQTT_NAME "sharonushusbabu"
#define MQTT_PASS "aio_nojn47dujDQMqfl9m78gDoC3Ljcz"
//the gpio pin D1
int led = D1;
WiFiClient client;
Adafruit_MQTT_Client mqtt(&client, MQTT_SERV, MQTT_PORT, MQTT_NAME, MQTT_PASS);
Adafruit_MQTT_Subscribe onoff = Adafruit_MQTT_Subscribe(&mqtt, MQTT_NAME "/feeds/ONOF");
Adafruit_MQTT_Publish LightsStatus = Adafruit_MQTT_Publish(&mqtt, MQTT_NAME "/feeds/LightsStatus");
void setup()
{
Serial.begin(9600);
pinMode(LED_BUILTIN, OUTPUT);
//Connect to WiFi
Serial.print("\n\nConnecting Wifi>");
WiFi.begin(WIFI_SSID, WIFI_PASS);
digitalWrite(LED_BUILTIN, LOW);
// Wait for the WiFi to be connected
while (WiFi.status() != WL_CONNECTED)
{
Serial.print(">");
delay(50);
}
// Now connected
Serial.println("OK!");
//Subscribe to the onoff topic
mqtt.subscribe(&onoff);
pinMode(led, OUTPUT);
digitalWrite(LED_BUILTIN, HIGH);
digitalWrite(led, LOW);
}
void loop()
{
//Connect/Reconnect to MQTT
MQTT_connect();
//Read from our subscription queue until we run out, or
//wait up to 5 seconds for subscription to update
Adafruit_MQTT_Subscribe * subscription;
while ((subscription = mqtt.readSubscription(5000)))
{
//If we're in here, a subscription updated...
if (subscription == &onoff)
{
//Print the new value to the serial monitor
Serial.print("onoff: ");
Serial.println((char*) onoff.lastread);
//If the new value is "ON", turn the light on.
//Otherwise, turn it off.
if (!strcmp((char*) onoff.lastread, "ON"))
{
//active low logic
digitalWrite(led, HIGH);
LightsStatus.publish("ON");
}
else if (!strcmp((char*) onoff.lastread, "OFF"))
{
digitalWrite(led, LOW);
LightsStatus.publish("OFF");
}
else
{
LightsStatus.publish("ERROR");
}
}
else
{
//LightsStatus.publish("ERROR");
}
}
}
void MQTT_connect()
{
// Stop and return, if already connected
if (mqtt.connected() && mqtt.ping())
{
//mqtt.disconnect();
return;
}
int8_t ret;
mqtt.disconnect();
Serial.print("Connecting to MQTT... ");
uint8_t retries = 3;
while ((ret = mqtt.connect()) != 0) // connect will return 0 for connected
{
Serial.println(mqtt.connectErrorString(ret));
Serial.println("Retrying MQTT connection in 5 seconds...");
mqtt.disconnect();
delay(5000); // wait 5 seconds
retries--;
if (retries == 0)
{
ESP.reset();
}
}
Serial.println("MQTT Connected!");
}
| 22.063492
| 99
| 0.64964
|
a533feedb9862d3683dff0c632b42e5b484d8896
| 636
|
ino
|
Arduino
|
eeprom1.ino
|
JKUATSES/2021-memoryDevices
|
a86b780f23e0f4c121efafc44acb96d31bab5a4e
|
[
"BSD-2-Clause"
] | null | null | null |
eeprom1.ino
|
JKUATSES/2021-memoryDevices
|
a86b780f23e0f4c121efafc44acb96d31bab5a4e
|
[
"BSD-2-Clause"
] | 4
|
2021-04-13T19:07:14.000Z
|
2021-04-13T19:12:20.000Z
|
eeprom1.ino
|
JKUATSES/2021-memoryDevices
|
a86b780f23e0f4c121efafc44acb96d31bab5a4e
|
[
"BSD-2-Clause"
] | null | null | null |
#include <EEPROM.h>
void setup() {
// put your setup code here, to run once:
}
void loop() {
// put your main code here, to run repeatedly:
}
void EEPROM_writeDouble(int address, double value)
{
byte* p = (byte*)(void*)&value;
for (int i = 0; i < sizeof(value); i++)
{
EEPROM.write(address++, *p++);
}
}
double EEPROM_readDouble(int address)
{
double value = 0.0;
byte* p = (byte*)(void*)&value;
for (int i = 0; i < sizeof(value); i++)
{
*p++ = EEPROM.read(address++);
}
return value;
}
| 22.714286
| 53
| 0.485849
|
48ae56018330a302100bad3849605d32cbe1b2fa
| 9,748
|
ino
|
Arduino
|
hammy.ino
|
davekiss/hammy
|
f137b38c436740f4f92159b02493d5de497364b2
|
[
"MIT"
] | null | null | null |
hammy.ino
|
davekiss/hammy
|
f137b38c436740f4f92159b02493d5de497364b2
|
[
"MIT"
] | null | null | null |
hammy.ino
|
davekiss/hammy
|
f137b38c436740f4f92159b02493d5de497364b2
|
[
"MIT"
] | null | null | null |
// Make sure to remove wire in pin 10 to
// successfully upload the code to the Arduino.
#include <SoftwareSerial.h>
#include <DFRobotDFPlayerMini.h>
SoftwareSerial mySoftwareSerial(2, 3); // RX, TX
// Alias mp3 library as Player
DFRobotDFPlayerMini Player;
const int blueLedPin1 = 5;
const int blueLedPin2 = 6;
const int blueLedPin3 = 9;
const int blueLedPin4 = 10;
const int redLedPin1 = 7;
const int redLedPin2 = 8;
const int redLedPin3 = 11;
const int redLedPin4 = 13;
// Switch reads from pin 12
const int onOffSwitchPin = 4;
const int shelfSwitchPin = 12;
// Variables will change:
int shelfSwitchState; // the current reading from the input pin
int lastShelfSwitchState = LOW; // the previous reading from the input pin
// the following variables are unsigned longs because the time, measured in
// milliseconds, will quickly become a bigger number than can be stored in an int.
unsigned long lastDebounceTime = 0; // the last time the output pin was toggled
unsigned long debounceDelay = 50; // the debounce time; increase if the output flickers
/*
* Track 1: "A swing and a drive, to deep left, awaaay back, gone!"
* Track 2: "Swiiing and a miss, ballgame!"
* Track 3: "How about that?!"
* Track 4: "Strike three called!"
* Track 5: "Swung on and belted, to deep left, awaaay back, gone! To the home run porch!"
* Track 6: "And we're underway at the corner of Carnegie and Ontario"
* Track 7: "Swiiing and a miss!"
* Track 8: "Ballgame!"
* Track 9: "Swing and a high drive, deep right center, there she goes! A game winner!"
*/
int trackIndex;
int playbackComplete = 0;
unsigned long playbackStartedAt = 0;
unsigned long playbackTime = 0;
void setup() {
// initialize the switch pin as an input
pinMode(shelfSwitchPin, INPUT);
digitalWrite(shelfSwitchPin, HIGH);
pinMode(onOffSwitchPin, INPUT);
digitalWrite(onOffSwitchPin, HIGH);
// initialize the led pin as an output
pinMode(blueLedPin1, OUTPUT);
pinMode(blueLedPin2, OUTPUT);
pinMode(blueLedPin3, OUTPUT);
pinMode(blueLedPin4, OUTPUT);
pinMode(redLedPin1, OUTPUT);
pinMode(redLedPin2, OUTPUT);
pinMode(redLedPin3, OUTPUT);
pinMode(redLedPin4, OUTPUT);
// Choose a random seed to base the track randomization
randomSeed(analogRead(0));
mySoftwareSerial.begin(9600);
Serial.begin(115200);
Serial.println();
Serial.println(F("DFRobot DFPlayer Mini Demo"));
Serial.println(F("Initializing DFPlayer ... (May take 3~5 seconds)"));
if (!Player.begin(mySoftwareSerial)) { //Use softwareSerial to communicate with mp3.
Serial.println(F("Unable to begin:"));
Serial.println(F("1.Please recheck the connection!"));
Serial.println(F("2.Please insert the SD card!"));
while(true){
delay(0); // Code to compatible with ESP8266 watch dog.
}
}
Serial.println(F("DFPlayer Mini online."));
Player.volume(30); //Set volume value. From 0 to 30
}
void loop() {
// read the state of the switch on pin 12 into a local variable:
int reading = digitalRead(shelfSwitchPin);
// If player is playing, set playback time.
if (playbackStartedAt > 0) {
playbackTime = millis() - playbackStartedAt;
setTrackSpecificLighting(trackIndex, playbackTime);
}
// check to see if a beer can was just dispensed.
// (i.e. the input went from LOW to HIGH), and you've waited long enough
// since the last press to ignore any noise:
// If the switch changed, due to noise or pressing:
if (reading != lastShelfSwitchState) {
// reset the debouncing timer
lastDebounceTime = millis();
}
if ((millis() - lastDebounceTime) > debounceDelay) {
// whatever the reading is at, it's been there for longer than the debounce
// delay, so take it as the actual current state:
// if the shelf switch state has changed:
if (reading != shelfSwitchState) {
shelfSwitchState = reading;
int onOffSwitchState = digitalRead(onOffSwitchPin);
Serial.print(F("Power switch is "));
Serial.println(onOffSwitchState);
// only trigger the audio if the new button state is HIGH
if (shelfSwitchState == HIGH) {
if (onOffSwitchState == HIGH) {
// select a random track from 1-9
trackIndex = random(1, 10);
Player.play(trackIndex);
playbackStartedAt = millis();
playbackComplete = 0;
Serial.print(F("Now playing: Track "));
Serial.println(trackIndex);
// Turn the lights on
// fade in from min to max in increments of 5 points:
for (int fadeValue = 0 ; fadeValue <= 255; fadeValue += 5) {
// sets the value (range from 0 to 255):
analogWrite(blueLedPin1, fadeValue);
analogWrite(blueLedPin2, fadeValue);
analogWrite(blueLedPin3, fadeValue);
analogWrite(blueLedPin4, fadeValue);
// wait for 30 milliseconds to see the dimming effect
delay(30);
}
} else {
// Lights only
// Turn the lights on
// fade in from min to max in increments of 5 points:
for (int fadeValue = 0 ; fadeValue <= 255; fadeValue += 5) {
// sets the value (range from 0 to 255):
analogWrite(blueLedPin1, fadeValue);
analogWrite(blueLedPin2, fadeValue);
analogWrite(blueLedPin3, fadeValue);
analogWrite(blueLedPin4, fadeValue);
// wait for 30 milliseconds to see the dimming effect
delay(30);
}
strobeRedLeds();
delay(2000);
// fade out from max to min in increments of 5 points:
for (int fadeValue = 255 ; fadeValue >= 0; fadeValue -= 5) {
// sets the value (range from 0 to 255):
analogWrite(blueLedPin1, fadeValue);
analogWrite(blueLedPin2, fadeValue);
analogWrite(blueLedPin3, fadeValue);
analogWrite(blueLedPin4, fadeValue);
// wait for 30 milliseconds to see the dimming effect
delay(30);
}
} // endif
}
}
}
// save the reading. Next time through the loop, it'll be the lastShelfSwitchState:
lastShelfSwitchState = reading;
if (Player.available()) {
printDetail(Player.readType(), Player.read()); //Print the detail message from DFPlayer to handle different errors and states.
}
}
// No special lighting for track 6, 7, 8
void setTrackSpecificLighting(int trackIndex, unsigned long playbackTime) {
switch(trackIndex) {
case 1:
if (playbackTime > 4400) {
Serial.println(F("Gone!")); // good
strobeRedLeds();
}
break;
case 2:
if (playbackTime > 1700) {
Serial.println(F("Ballgame!")); //good
strobeRedLeds();
}
break;
case 3:
strobeRedLeds();
// flicker whole time
break;
case 4:
if (playbackTime > 1700) {
Serial.println(F("Called!")); //goood
strobeRedLeds();
}
break;
case 5:
if (playbackTime > 5000) {
Serial.println(F("Gone!"));
strobeRedLeds();
}
break;
case 9:
if (playbackTime > 3500) {
Serial.println(F("There she goes!")); // good
strobeRedLeds();
}
break;
default:
break;
}
}
void strobeRedLeds() {
for(int i = 0; i < 10; i += 1) {
digitalWrite(redLedPin1, !digitalRead(redLedPin1));
delay(50);
digitalWrite(redLedPin2, !digitalRead(redLedPin2));
delay(50);
digitalWrite(redLedPin3, !digitalRead(redLedPin3));
delay(50);
digitalWrite(redLedPin4, !digitalRead(redLedPin4));
delay(50);
}
}
void printDetail(uint8_t type, int value) {
switch (type) {
case TimeOut:
Serial.println(F("Time Out!"));
break;
case WrongStack:
Serial.println(F("Stack Wrong!"));
break;
case DFPlayerCardInserted:
Serial.println(F("Card Inserted!"));
break;
case DFPlayerCardRemoved:
Serial.println(F("Card Removed!"));
break;
case DFPlayerCardOnline:
Serial.println(F("Card Online!"));
break;
case DFPlayerPlayFinished:
Serial.print(F("Number:"));
Serial.print(value);
Serial.println(F(" Play Finished!"));
// Fixes issue with this callback being called twice consecutively.
if (playbackComplete == 0) {
// fade out from max to min in increments of 5 points:
for (int fadeValue = 255 ; fadeValue >= 0; fadeValue -= 5) {
// sets the value (range from 0 to 255):
analogWrite(blueLedPin1, fadeValue);
analogWrite(blueLedPin2, fadeValue);
analogWrite(blueLedPin3, fadeValue);
analogWrite(blueLedPin4, fadeValue);
// wait for 30 milliseconds to see the dimming effect
delay(30);
}
}
playbackStartedAt = 0;
playbackComplete = 1;
break;
case DFPlayerError:
Serial.print(F("DFPlayerError:"));
switch (value) {
case Busy:
Serial.println(F("Card not found"));
break;
case Sleeping:
Serial.println(F("Sleeping"));
break;
case SerialWrongStack:
Serial.println(F("Get Wrong Stack"));
break;
case CheckSumNotMatch:
Serial.println(F("Check Sum Not Match"));
break;
case FileIndexOut:
Serial.println(F("File Index Out of Bound"));
break;
case FileMismatch:
Serial.println(F("Cannot Find File"));
break;
case Advertise:
Serial.println(F("In Advertise"));
break;
default:
break;
}
break;
default:
break;
}
}
| 29.90184
| 130
| 0.625256
|
e22b6400b50eb3a74497933b61af97a3cac03a5c
| 1,736
|
ino
|
Arduino
|
examples/Simulator/Simulator.ino
|
yves-ledermann/FlowMeter
|
ee5e14801131b8129159e80a769c092e4286e616
|
[
"MIT"
] | null | null | null |
examples/Simulator/Simulator.ino
|
yves-ledermann/FlowMeter
|
ee5e14801131b8129159e80a769c092e4286e616
|
[
"MIT"
] | null | null | null |
examples/Simulator/Simulator.ino
|
yves-ledermann/FlowMeter
|
ee5e14801131b8129159e80a769c092e4286e616
|
[
"MIT"
] | null | null | null |
#include <FlowMeter.h> // https://github.com/sekdiy/FlowMeter
// let's provide our own sensor properties, including calibration points for error correction
FlowSensorProperties MySensor = {60.0f, 4.5f, {1.2, 1.1, 1.05, 1, 1, 1, 1, 0.95, 0.9, 0.8}};
// let's pretend there's a flow sensor connected to pin 3
FlowMeter Meter = FlowMeter(3, MySensor);
void setup() {
// prepare serial communication
Serial.begin(9600);
// sometimes initializing the gear generates some pulses that we should ignore
Meter.reset();
}
void loop() {
// randomly change simulation period and pulse rate
long frequency = random(MySensor.capacity * MySensor.kFactor); // Hz
long period = random(3 * frequency, 5000); // ms
// simulate random flow meter pulses within a random period
for (long i = 0; i < (long) ((float) period * (float) frequency / 1000.0f); i++) {
Meter.count();
}
// wait that random period
delay(period);
// process the counted ticks
Meter.tick(period);
// output some measurement result
Serial.println("FlowMeter - period: " + String(Meter.getCurrentDuration() / 1000.0f, 3) + "s, " +
"frequency: " + String(Meter.getCurrentFrequency(), 0) + "Hz, " +
"volume: " + Meter.getCurrentVolume() + "l, " +
"flow rate: " + Meter.getCurrentFlowrate() + "l/min, " +
"error: " + Meter.getCurrentError() + "%, " +
"total duration: " + Meter.getTotalDuration() / 1000.0f + "s, " +
"total volume: " + Meter.getTotalVolume() + "l, " +
"average flow rate: " + Meter.getTotalFlowrate() + "l/min, " +
"average error: " + Meter.getTotalError() + "%.");
}
| 39.454545
| 99
| 0.602535
|
1f21ad6985069bab1f723e7fb6d7b1b80ed1f1d0
| 4,056
|
ino
|
Arduino
|
old codes/_9_AvoidObstacleRobot/_9_AvoidObstacleRobot.ino
|
k24koba/Lambda
|
ca45bb8d68251b7871e5edf58253b76f0898d272
|
[
"BSD-3-Clause"
] | null | null | null |
old codes/_9_AvoidObstacleRobot/_9_AvoidObstacleRobot.ino
|
k24koba/Lambda
|
ca45bb8d68251b7871e5edf58253b76f0898d272
|
[
"BSD-3-Clause"
] | null | null | null |
old codes/_9_AvoidObstacleRobot/_9_AvoidObstacleRobot.ino
|
k24koba/Lambda
|
ca45bb8d68251b7871e5edf58253b76f0898d272
|
[
"BSD-3-Clause"
] | null | null | null |
#include <Servo.h>//ライブラリの読み込み
#define PBS1 0//置き換え
#define PBS2 1
#define Limit 2
#define analogPin 0
int value = 0;
int s1, s2, s3;
Servo servo0;
void setup()
{
pinMode(PBS1, INPUT);
pinMode(PBS2, INPUT);
pinMode(Limit, INPUT);
pinMode(6, OUTPUT);
DDRB = B1111;//ポートBの入出力を設定
servo0.attach(6);
}
void loop()
{
s1 = digitalRead(PBS1);//ここから障害物を回避する動作
//PBS1の値を読み取ってS1に代入
if (s1 == 0)//S1が0、すなわちPBS1がオンなら次へ
{
while (1)//ループ
{
PORTB = 0x05;//PORTBに出力。ロボット前進。
servo0.write(170);//サーボ出力170度。測距モジュールが左を向く。
delay(500);
value = analogRead(analogPin);//AD変換。デジタル値をvalueに代入
if (value >= 266)//valueが266以上なら次へ
{
PORTB = 0x09; //ロボット右旋回
delay(500);
}
///////////////////////////////////////////////////////////////////////////////////
PORTB = 0x05; //ロボット前進
servo0.write(90);//測距正面
delay(500);
value = analogRead(analogPin);//AD変換。デジタル値をvalueに代入
if (value >= 409)//valueが409以上なら次へ
{
PORTB = 0x0a; //ロボット後進
delay(1000);
PORTB = 0x06; //ロボット左旋回
delay(500);
}
///////////////////////////////////////////////////////////////////////////////////
PORTB = 0x05;//PORTBに出力。ロボット前進。
servo0.write(10);//測距右。
delay(500);
value = analogRead(analogPin);//AD変換。デジタル値をvalueに代入
if (value >= 266)//valueが266以上なら次へ
{
PORTB = 0x06; //ロボット左旋回
delay(500);
}
///////////////////////////////////////////////////////////////////////////////////
PORTB = 0x05; //ロボット前進
servo0.write(90);//測距正面
delay(500);
value = analogRead(analogPin);//AD変換。デジタル値をvalueに代入
if (value >= 409)//valueが409以上なら次へ
{
PORTB = 0x0a; //ロボット後進
delay(1000);
PORTB = 0x09; //ロボット右旋回
delay(500);
}
}
}
//////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////
s2 = digitalRead(PBS2); //ここからは障害物へアタック PBS2の値を読み取ってS2に代入
if (s2 == 0) //s2=0すなわちPBS2がONなら次へ
{
while (2)//ループ
{
PORTB = 0x05;//PORTBに出力。ロボット前進。
servo0.write(170);//サーボ出力170度。測距モジュールが左を向く。
delay(500);
value = analogRead(analogPin);//AD変換。デジタル値をvalueに代入
if (value >= 266)//valueが266以上なら次へ
{
PORTB = 0x0f; //ロボットブレーキ
delay(500);
PORTB = 0x0a; //ロボット後退
delay(500);
PORTB = 0x06; //ロボット左旋回
delay(300);
}
///////////////////////////////////////////////////////////////////////////////////
PORTB = 0x05; //ロボット前進
servo0.write(90);//測距正面
delay(500);
s3 = digitalRead(Limit); //Limitの値を読み取ってs3へ代入
if (s3 == 0)//s3が0すなわちマイクロスイッチがONならば次へ
{
PORTB = 0x0f; //ロボットブレーキ
delay(500);
PORTB = 0x0a; //ロボット後退
delay(500);
PORTB = 0x09; //ロボット右旋回
delay(300);
}
///////////////////////////////////////////////////////////////////////////////////
PORTB = 0x05; //ロボット前進
servo0.write(10);//測距右
delay(500);
s3 = digitalRead(Limit); //Limitの値を読み取ってs3へ代入
if (value >= 266)//valueが266以上なら次へ
{
PORTB = 0x0f; //ロボットブレーキ
delay(500);
PORTB = 0x0a; //ロボット後退
delay(500);
PORTB = 0x09; //ロボット右旋回
delay(300);
}
///////////////////////////////////////////////////////////////////////////////////
PORTB = 0x05; //ロボット前進
servo0.write(90);//測距正面
delay(500);
s3 = digitalRead(Limit); //Limitの値を読み取ってs3へ代入
if (s3 == 0)//s3が0すなわちマイクロスイッチがONならば次へ
{
PORTB = 0x0f; //ロボットブレーキ
delay(500);
PORTB = 0x0a; //ロボット後退
delay(500);
PORTB = 0x06; //ロボット左旋回
delay(300);
}
}
}
}
| 22.163934
| 86
| 0.42283
|
d51405f14a7e36b01b378eb4de84800180bbb3b6
| 1,218
|
ino
|
Arduino
|
Other/DS1307RTC/DS1307RTC.ino
|
vAlmaraz/arduino-examples
|
46191c2a39d3dbb355fbc2178535dd1c36334788
|
[
"MIT"
] | 1
|
2016-01-23T12:38:06.000Z
|
2016-01-23T12:38:06.000Z
|
Other/DS1307RTC/DS1307RTC.ino
|
vAlmaraz/arduino-examples
|
46191c2a39d3dbb355fbc2178535dd1c36334788
|
[
"MIT"
] | null | null | null |
Other/DS1307RTC/DS1307RTC.ino
|
vAlmaraz/arduino-examples
|
46191c2a39d3dbb355fbc2178535dd1c36334788
|
[
"MIT"
] | null | null | null |
#include <Time.h>
#include <TimeLib.h>
#include <TimeAlarms.h>
void setup() {
Serial.begin(9600);
// set time: HH, mm, ss, dd, MM, YY
setTime(17,03,0,10,2,17);
// create the alarms
// 8:30am every day
Alarm.alarmRepeat(17, 04, 0, alarm1);
// 5:45pm every day
Alarm.alarmRepeat(17, 05, 0, alarm2);
// 8:30:30 every Saturday
Alarm.alarmRepeat(dowFriday, 8, 30, 30, alarm3);
// timer for every 15 seconds
Alarm.timerRepeat(15, Repeats);
// called once after 10 seconds
Alarm.timerOnce(10, OnceOnly);
}
void loop() {
digitalClockDisplay();
// wait one second between clock display
Alarm.delay(1000);
}
void digitalClockDisplay() {
// digital clock display of the time
Serial.print(hour());
printDigits(minute());
printDigits(second());
Serial.println();
}
void printDigits(int digits) {
Serial.print(":");
if(digits < 10) {
Serial.print('0');
}
Serial.print(digits);
}
void alarm1(){
Serial.println("Alarm: 1");
}
void alarm2(){
Serial.println("Alarm: 2");
}
void alarm3(){
Serial.println("Alarm: 3");
}
void Repeats() {
Serial.println("15 second timer");
}
void OnceOnly() {
Serial.println("This timer only triggers once");
}
| 18.738462
| 52
| 0.642857
|
06feb7ed7dd03bd6c35a980d6df1e76800575678
| 12,806
|
ino
|
Arduino
|
IK_robot_arm/IK_robot_arm.ino
|
abhijit-pamarty/IK-3DOF-Robot-arm
|
5642aa20b572c7b99d4109d817c855e4a0a6e6e9
|
[
"MIT"
] | 2
|
2021-04-02T03:01:42.000Z
|
2021-12-08T10:26:23.000Z
|
IK_robot_arm/IK_robot_arm.ino
|
abhijit-pamarty/IK-3DOF-Robot-arm
|
5642aa20b572c7b99d4109d817c855e4a0a6e6e9
|
[
"MIT"
] | 4
|
2019-12-21T04:49:48.000Z
|
2020-01-04T14:59:53.000Z
|
IK_robot_arm/IK_robot_arm.ino
|
abhijit-pamarty/IK-3DOF-Robot-arm
|
5642aa20b572c7b99d4109d817c855e4a0a6e6e9
|
[
"MIT"
] | 1
|
2021-04-02T03:01:44.000Z
|
2021-04-02T03:01:44.000Z
|
//Inverse kinematics Robot arm with 3 degrees of freedom
//_________________________________________________________________________________________________________________________________________________________________________
#include<Servo.h>
#include<math.h>
//_________________________________________________________________________________________________________________________________________________________________________
//Pin and arm length definitions
#define x_pin A1
#define y_pin A2
#define z_pin A3
#define switch_pin_1 4
#define servo_pin_1 5
#define servo_pin_2 6
#define servo_pin_3 7
float b_length = 5.5, f_length = 9.35;
float current_x, current_y, current_z;
float previous_x, previous_y, previous_z;
float increment = 0; // put this to zero if you want to use joysticks
float pi = 3.14159;
Servo servo_1, servo_2, servo_3;
struct var_5 // to return multiple variables
{
float var1, var2, var3, var4, var5;
};
//_________________________________________________________________________________________________________________________________________________________________________
//setup
void setup() {
Serial.begin(9600); //begin serial
float reach = pow(pow((f_length + b_length),2),0.5);
Serial.println("reach");
Serial.print(reach);
current_x = 8;
current_y = 0;
current_z = 5; //Move the arm to the initial position
delay(100);
previous_x = 8;
previous_y = 0;
previous_z = 5; //And say that position before t = 0 was also the same
servo_1.attach(servo_pin_1); //attach servos to their respective pins
servo_2.attach(servo_pin_2);
servo_3.attach(servo_pin_3);
}
//_________________________________________________________________________________________________________________________________________________________________________
//Function to find the intersection of two circles
var_5 circle_intersection(float f1 ,float f2,float o1 ,float o2 ,float l1 ,float l2 )
{ var_5 points;
float R = pow((f1*f1 + f2*f2),(0.5));
float x_cor = f1 - o1;
float y_cor = f2 - o2;
float rot1 = (l1*l1 - l2*l2 + R*R)/(2*R);
float rot2 = pow((l1*l1 - rot1*rot1),0.5);
float x1 = ((rot1/R) * (x_cor)) + ((rot2/R) * (y_cor)) + o1;
float y1 = ((rot1/R) * (y_cor)) - ((rot2/R) * (x_cor)) + o2;
float x2 = ((rot1/R) * (x_cor)) - ((rot2/R) * (y_cor)) + o1;
float y2= ((rot1/R) * (y_cor)) + ((rot2/R) * (x_cor)) + o2;
Serial.print("x1:");
Serial.println(x1);
Serial.print("x2:");
Serial.println(x2);
Serial.print("y1:");
Serial.println(y1);
Serial.print("y2:");
Serial.println(y2);
points.var1 = x1;
points.var2 = y1;
points.var3 = x2;
points.var4 = y2;
return points; //Returns two points, because almost every circle has two intersection points.
}
//_________________________________________________________________________________________________________________________________________________________________________
//Function to create a line
float generate_line(float x1,float y1, float x2, float y2)
{
float slope;
if (x2 != x1)
{
slope = (y2 - y1)/(x2 - x1);
Serial.println("if called");
Serial.print("slope:");
Serial.println(slope);
}
else
{
slope = 100000; //some arbitrarily high slope
Serial.println("else called");
}
Serial.print("slope:");
Serial.println(slope);
return slope;
}
//_________________________________________________________________________________________________________________________________________________________________________
//Function to find angle between two lines
float ang_between_lines(float m1,float m2)
{
return atan((m1-m2)/(1+(m1*m2)));
}
//_________________________________________________________________________________________________________________________________________________________________________
//Subfunction in case of physical constraints
//Designed to maintain position
var_5 error_protocol(float init_x,float init_y,float init_z)
{
float base_x = 0, base_y = 0, base_z = 0;
float R_init = pow((pow((init_x - base_x),2) + pow((init_y - base_y),2)),0.5);
float theta = atan((init_y - base_y)/(init_x - base_x));
float Z_init = init_z - base_z;
var_5 angles;
angles = extension(R_init, Z_init, R_init, Z_init); // shoulder angle is var1, elbow angle var2.
angles.var5 = angles.var2;
angles.var4 = angles.var1;
angles.var1 = theta;
angles.var2 = angles.var4;
angles.var3 = angles.var5;
return angles;
}
//_________________________________________________________________________________________________________________________________________________________________________
//Function to find angle between two lines
var_5 extension(float X_cord, float Y_cord, float target_X, float target_Y)
{ var_5 points;
points = circle_intersection(target_X, target_Y, 0, 0, f_length, b_length);
float x1 = points.var1 ;
float x2 = points.var3;
float y1 = points.var2;
float y2 = points.var4;
Serial.print("x1:");
Serial.println(x1);
Serial.print("x2:");
Serial.println(x2);
Serial.print("y1:");
Serial.println(y1);
Serial.print("y2:");
Serial.println(y2);
//find out optimal point, that is, point closest to the current position
float optimal_x, optimal_y;
float min_distance = 10000000.0; //some arbitrary value
float distance_p1 = pow((pow((x1 - X_cord),2) + pow((y1 - Y_cord),2)),0.5);
float distance_p2 = pow((pow((x2 - X_cord),2) + pow((y2 - Y_cord),2)),0.5);
if (distance_p1 >= distance_p2)
{
optimal_x = x2;
optimal_y = y2;
}
else
{
optimal_x = x1;
optimal_y = y1;
}
float bicep_m, forearm_m;
bicep_m = generate_line(0, 0, optimal_x, optimal_y);
forearm_m = generate_line(optimal_x, optimal_y, target_X, target_Y);
float shoulder_angle = ang_between_lines(bicep_m, 0);
float elbow_angle = ang_between_lines(forearm_m, bicep_m);
Serial.print("shoulder angle:");
Serial.println(shoulder_angle);
Serial.print("elbow angle:");
Serial.println(elbow_angle);
var_5 angles;
angles.var1 = shoulder_angle;
angles.var2 = elbow_angle;
return angles;
}
//_________________________________________________________________________________________________________________________________________________________________________
//Function to calculate angles of servos
var_5 Inverse_kinematics (float final_x, float final_y, float final_z, float init_x, float init_y, float init_z)
{
float error_check = 0.0;
float servo_angle_1 = 0, servo_angle_2 = 0, servo_angle_3 = 0;
float check_bounds = pow((pow(final_x,2) + pow(final_y,2) + pow(final_z,2)),0.5);
bool check_floor = bool(final_z > 0);
float base_size = abs(f_length - b_length);
float reach = pow((f_length + b_length),2);
var_5 servo_angles;
if (check_bounds > base_size and check_bounds < reach and check_floor and final_y >= 0)
{
float base_x = 0, base_y = 0, base_z = 0;
float R_init = pow((pow((init_x - base_x),2) + pow((init_y - base_y),2)),0.5);
float R_fin = pow((pow((final_x - base_x),2) + pow((final_y - base_y),2)),0.5);
float theta = atan((final_y - base_y)/(final_x - base_x));
float Z_init = init_z - base_z;
float Z_fin = final_z - base_z;
var_5 angles;
angles = extension(R_init, Z_init, R_fin, Z_fin);
servo_angle_1 = theta;
servo_angle_2 = angles.var1;
servo_angle_3 = angles.var2;
servo_angles.var1 = servo_angle_1;
servo_angles.var2 = servo_angle_2;
servo_angles.var3 = servo_angle_3;
servo_angles.var4 = error_check;
}
else if (check_bounds < base_size)
{
Serial.println("Action terminated, collision with base");
servo_angles = error_protocol(init_x, init_y, init_z);
servo_angles.var4 = 1.0;
}
else if ( check_bounds > reach or final_y < 0)
{
Serial.println("Action terminated, not enough reach");
Serial.println(check_bounds);
servo_angles = error_protocol(init_x, init_y, init_z);
servo_angles.var4 = 1.0;
}
else if (check_floor == 0)
{
Serial.println("Action terminated, collision with floor");
servo_angles = error_protocol(init_x, init_y, init_z);
servo_angles.var4 = 1.0;
}
else
{
Serial.println("Unknown error, please terminate the program");
servo_angles = error_protocol(init_x, init_y, init_z);
servo_angles.var4 = 1.0;
}
return servo_angles;
}
//_________________________________________________________________________________________________________________________________________________________________________
//loop function
void loop() {
float servo_1_angle, servo_2_angle, servo_3_angle, error_check;
Serial.println(current_x);
Serial.println(current_y);
Serial.println(current_z);
Serial.println("");
var_5 servo_angles;
servo_angles = Inverse_kinematics( current_x, current_y, current_z, previous_x, previous_y, previous_z);
servo_1_angle = servo_angles.var1;
servo_2_angle = servo_angles.var2;
servo_3_angle = servo_angles.var3;
error_check = servo_angles.var4;
servo_1_angle = 180/3.14159 * servo_1_angle;
if (servo_1_angle < 0)
{
servo_1_angle = 180 + servo_1_angle;
}
else
{
servo_1_angle = servo_1_angle;
}
servo_2_angle = 180/3.14159 * servo_2_angle;
if (servo_2_angle < 0)
{
servo_2_angle = 180 + servo_2_angle;
}
else
{
servo_2_angle = servo_2_angle;
}
servo_2_angle = 180 - servo_2_angle;
servo_3_angle = 180/3.14159 * servo_3_angle;
if (servo_3_angle < 0)
{
servo_3_angle = 180 + servo_3_angle;
}
else
{
servo_3_angle = servo_3_angle;
}
error_check = int(error_check);
float joystick_1 = 0, joystick_2 = 0, joystick_3 = 0;
joystick_1 = analogRead(x_pin);
joystick_2 = analogRead(y_pin);
joystick_3 = analogRead(z_pin);
delay(10);
joystick_1 = (joystick_1/1023);
joystick_2 = (joystick_2/1023);
joystick_3 = (joystick_3/1023);
if (joystick_1 < 0.2 and joystick_1 >-0.2)
{
joystick_1 = 0;
}
if (joystick_2 < 0.2 and joystick_2 >-0.2)
{
joystick_2 = 0;
}
if (joystick_3 < 0.3 and joystick_3 >-0.3)
{
joystick_3 = 0;
}
if (error_check == 0)
{
for( int i = 0; i <= servo_1_angle; i++);
{
servo_1.write(servo_1_angle);
delay(100);
}
for( int i = 0; i <= servo_2_angle; i++);
{
servo_2.write(servo_2_angle);
delay(100);
}
for( int i = 0; i <= servo_3_angle; i++);
{
servo_3.write(servo_3_angle);
delay(100);
}
current_x = increment*joystick_1 + current_x;
current_y = increment*joystick_2 + current_y;
current_z = increment*joystick_3 + current_z;
previous_x = current_x;
previous_y = current_y;
previous_z = current_z;
}
else
{
previous_x = current_x;
previous_y = current_y;
previous_z = current_z;
current_x = current_x - 1;
current_y = current_y - 1;
Serial.print("ERROR");
for( int i = 0; i <= servo_1_angle; i++);
{
servo_1.write(servo_1_angle);
delay(100);
}
for( int i = 0; i <= servo_2_angle; i++);
{
servo_2.write(servo_2_angle);
delay(100);
}
for( int i = 0; i <= servo_3_angle; i++);
{
servo_3.write(servo_3_angle);
delay(100);
}
}
Serial.print("servo 1's angle:");
Serial.println(servo_1_angle);
Serial.print("servo 2's angle:");
Serial.println(servo_2_angle);
Serial.print("servo 3's angle:");
Serial.println(servo_3_angle);
delay(1000000);
}
| 27.718615
| 172
| 0.634859
|
7392605f11a765eda04296a31d3bb01048dd3459
| 5,392
|
ino
|
Arduino
|
RFLink_ESP/RFLink_ESP.ino
|
Stef-aap/Domotica
|
dac0bd550ea08e4c1cd0e0aa8d04d82a9b2d4d56
|
[
"MIT"
] | 1
|
2019-01-29T13:05:51.000Z
|
2019-01-29T13:05:51.000Z
|
RFLink_ESP/RFLink_ESP.ino
|
Stef-aap/Domotica
|
dac0bd550ea08e4c1cd0e0aa8d04d82a9b2d4d56
|
[
"MIT"
] | null | null | null |
RFLink_ESP/RFLink_ESP.ino
|
Stef-aap/Domotica
|
dac0bd550ea08e4c1cd0e0aa8d04d82a9b2d4d56
|
[
"MIT"
] | null | null | null |
// ****************************************************************************
// Version info
// ****************************************************************************
#define Version "2.0"
#define Revision 0x01
#define Build 0x01
// ****************************************************************************
// used in Raw signal
//
// original: 20=8 bits. Minimal number of bits*2 that need to have been received
// before we spend CPU time on decoding the signal.
//
// MAX might be a little to low ??
// ****************************************************************************
#define MIN_RAW_PULSES 26 //20 // =8 bits. Minimal number of bits*2 that need to have been received before we spend CPU time on decoding the signal.
#define MAX_RAW_PULSES 150
// ****************************************************************************
#define MIN_PULSE_LENGTH 40 // Pulses shorter than this value in uSec. will be seen as garbage and not taken as actual pulses.
#define SIGNAL_TIMEOUT 7 // Timeout, after this time in mSec. the RF signal will be considered to have stopped.
#define RAW_BUFFER_SIZE 512 // Maximum number of pulses that is received in one go.
#define INPUT_COMMAND_SIZE 60 // Maximum number of characters that a command via serial can be.
// ****************************************************************************
// Global Variables
// ****************************************************************************
byte PKSequenceNumber = 0 ; // 1 byte packet counter
char PreFix [20] ;
unsigned long Last_Detection_Time = 0L ;
int Learning_Mode = 0 ; // always start in production mode
char pbuffer [ 60 ] ; // Buffer for printing data
char pbuffer2 [ 30 ] ;
char InputBuffer_Serial [ INPUT_COMMAND_SIZE ]; // Buffer for Seriel data
struct RawSignalStruct { // Raw signal variabelen places in a struct
int Number ; // Number of pulses, times two as every pulse has a mark and a space.
int Min ;
int Max ;
long Mean ;
unsigned long Time ; // Timestamp indicating when the signal was received (millis())
int Pulses [ RAW_BUFFER_SIZE + 2 ] ; // Table with the measured pulses in microseconds divided by RawSignal.Multiply. (halves RAM usage)
// First pulse is located in element 1. Element 0 is used for special purposes, like signalling the use of a specific plugin
} RawSignal= { 0, 0, 0, 0, 0L };
//} RawSignal={0,0,0,0,0,0L};
unsigned long Last_BitStream = 0L ; // holds the bitstream value for some plugins to identify RF repeats
bool Serial_Command = false ;
int SerialInByteCounter = 0 ; // number of bytes counter
byte SerialInByte ; // incoming character value
String Unknown_Device_ID = "" ;
// ***********************************************************************************
// File with the device registrations
// ***********************************************************************************
#include "RFLink_File.h"
_RFLink_File RFLink_File ; // ( "/RFLink.txt" ) ;
// ***********************************************************************************
// Hardware pins
// ***********************************************************************************
#ifdef ESP32
#define TRANSMIT_PIN 5 // Data to the 433Mhz transmitter on this pin
#define RECEIVE_PIN 19 // On this input, the 433Mhz-RF signal is received. LOW when no signal.
#else
#define TRANSMIT_PIN 5 // Data to the 433Mhz transmitter on this pin
#define RECEIVE_PIN 4 // On this input, the 433Mhz-RF signal is received. LOW when no signal.
#endif
// ***********************************************************************************
// ***********************************************************************************
#include "RFL_Protocols.h"
// ***********************************************************************************
// ***********************************************************************************
void setup() {
Serial.begin ( 57600 ) ;
RFLink_File.Begin () ;
pinMode ( RECEIVE_PIN, INPUT ) ;
pinMode ( TRANSMIT_PIN, OUTPUT ) ;
digitalWrite ( RECEIVE_PIN, INPUT_PULLUP ) ; // pull-up resister on (to prevent garbage)
// ********* PROTOCOL CLASSES, available and in this order ************
RFL_Protocols.Add ( new _RFL_Protocol_KAKU () ) ;
RFL_Protocols.Add ( new _RFL_Protocol_EV1527 () ) ;
RFL_Protocols.Add ( new _RFL_Protocol_Paget_Door_Chime () ) ;
RFL_Protocols.setup () ;
// ************************************************************************
delay ( 200 ) ;
Serial.printf ( "20;%02X;Nodo RadioFrequencyLink - MiRa V%s - R%02x\r\n",
PKSequenceNumber++, Version, Revision );
RawSignal.Time = millis() ;
}
// ***********************************************************************************
// ***********************************************************************************
void loop () {
if ( FetchSignal () ) {
RFL_Protocols.Decode ();
}
Handle_Serial () ;
}
| 46.886957
| 165
| 0.452522
|
dbb505ae478def17edd159b6e07c8f8505b1b219
| 2,220
|
ino
|
Arduino
|
examples/02.Advanced/MultiSensor/MultiSensor.ino
|
Serkora/VL53L1X_ULD
|
caa2bf99f50221b5af20583693c9da7cd07184bf
|
[
"BSD-3-Clause"
] | 10
|
2020-04-30T15:37:14.000Z
|
2022-02-07T14:47:27.000Z
|
examples/02.Advanced/MultiSensor/MultiSensor.ino
|
Serkora/VL53L1X_ULD
|
caa2bf99f50221b5af20583693c9da7cd07184bf
|
[
"BSD-3-Clause"
] | 3
|
2020-11-22T05:24:29.000Z
|
2021-09-14T19:16:24.000Z
|
examples/02.Advanced/MultiSensor/MultiSensor.ino
|
Serkora/VL53L1X_ULD
|
caa2bf99f50221b5af20583693c9da7cd07184bf
|
[
"BSD-3-Clause"
] | 6
|
2020-11-19T16:55:33.000Z
|
2022-03-01T08:39:37.000Z
|
/**
* This example contains a an example of using 2 sensors on the same I2C bus by using the XSHUT pin of one of the sensors
*/
#include "VL53L1X_ULD.h"
VL53L1X_ULD sensor_1;
VL53L1X_ULD sensor_2;
#define SENSOR_1_XSHUT 3
#define SENSOR_2_I2C_ADDRESS 0x55
void setup() {
Serial.begin(115200); // Start the serial port
Wire.begin(); // Initialize the I2C controller
// Turn off sensor 1 by pulling the XSHUT pin LOW
pinMode(SENSOR_1_XSHUT, OUTPUT);
digitalWrite(SENSOR_1_XSHUT, LOW);
// Initialize sensor 2
VL53L1_Error status = sensor_2.Begin(SENSOR_2_I2C_ADDRESS);
if (status != VL53L1_ERROR_NONE) {
// If the sensor could not be initialized print out the error code. -7 is timeout
Serial.println("Could not initialize sensor 2, error code: " + String(status));
while (1) {}
}
Serial.println("Sensor initialized");
// Set the I2C address of sensor 2 to a different address as the default.
sensor_2.SetI2CAddress(SENSOR_2_I2C_ADDRESS);
// Turn on sensor 1 by pulling the XSHUT pin HIGH
digitalWrite(SENSOR_1_XSHUT, HIGH);
// Initialize sensor 1
status = sensor_1.Begin();
if (status != VL53L1_ERROR_NONE) {
// If the sensor could not be initialized print out the error code. -7 is timeout
Serial.println("Could not initialize sensor 1, error code: " + String(status));
while (1) {}
}
Serial.println("Sensor initialized");
sensor_1.StartRanging();
sensor_2.StartRanging();
}
void loop() {
// Checking if data is available. This can also be done through the hardware interrupt
uint8_t dataReady_sensor_1 = false, dataReady_sensor_2 = false;
while(!dataReady_sensor_1 || !dataReady_sensor_2) {
sensor_1.CheckForDataReady(&dataReady_sensor_1);
sensor_2.CheckForDataReady(&dataReady_sensor_2);
delay(5);
}
// Get the results
uint16_t distance1, distance2;
sensor_1.GetDistanceInMm(&distance1);
sensor_2.GetDistanceInMm(&distance2);
Serial.println("Distance sensor 1 in mm: " + String(distance1));
Serial.println("Distance sensor 2 in mm: " + String(distance2));
// After reading the results reset the interrupt to be able to take another measurement
sensor_1.ClearInterrupt();
sensor_2.ClearInterrupt();
}
| 32.647059
| 121
| 0.73018
|
cfd6a06ab8badbe39b38a521381591d10beadbc4
| 1,009
|
ino
|
Arduino
|
examples/Unit/ULTRA/ULTRA.ino
|
MrARM/M5StickC
|
f21646109f7297db5d0668dce68389d37b00e156
|
[
"MIT"
] | null | null | null |
examples/Unit/ULTRA/ULTRA.ino
|
MrARM/M5StickC
|
f21646109f7297db5d0668dce68389d37b00e156
|
[
"MIT"
] | null | null | null |
examples/Unit/ULTRA/ULTRA.ino
|
MrARM/M5StickC
|
f21646109f7297db5d0668dce68389d37b00e156
|
[
"MIT"
] | null | null | null |
#include <M5StickC.h>
void setup() {
// put your setup code here, to run once:
M5.begin();
Wire.begin(32,33);
M5.Lcd.setRotation(3);
M5.Lcd.setCursor(25, 0, 4);
M5.Lcd.print("Ultrasonic");
}
float readEUS()
{
uint32_t data;
Wire.beginTransmission(0x57);
Wire.write(0x01);
Wire.endTransmission();
delay(120);
Wire.requestFrom(0x57,3);
data = Wire.read();data <<= 8;
data |= Wire.read();data <<= 8;
data |= Wire.read();
return float(data) / 1000;
}
void loop() {
float newvalue = 0;
while(1)
{
newvalue = readEUS();
M5.Lcd.setCursor(22,40,4);
if(( newvalue < 1500 )&&( newvalue > 20 ))
{
M5.Lcd.printf("%.2fmm",newvalue);
if(( newvalue < 100 )&&( newvalue > 20 ))
{
M5.Lcd.fillRect(128, 40, 15, 20, BLACK);
}
}
delay(100);
}
}
| 20.18
| 76
| 0.465808
|
2209f05d39580874da133a934498bd601f591161
| 1,352
|
ino
|
Arduino
|
IoTHub/_DEMO_DEVICES/Arduino-ESP8266-Secure-Azure-IoT-Hub-Client/AzureClient/Helpers.ino
|
tkopacz/2017IoTWorkshop
|
e386da4132ce781f55000a43b91f81855027047b
|
[
"MIT"
] | 1
|
2017-05-27T17:55:39.000Z
|
2017-05-27T17:55:39.000Z
|
IoTHub/_DEMO_DEVICES/Arduino-ESP8266-Secure-Azure-IoT-Hub-Client/AzureClient/Helpers.ino
|
tkopacz/2017IoTWorkshop
|
e386da4132ce781f55000a43b91f81855027047b
|
[
"MIT"
] | null | null | null |
IoTHub/_DEMO_DEVICES/Arduino-ESP8266-Secure-Azure-IoT-Hub-Client/AzureClient/Helpers.ino
|
tkopacz/2017IoTWorkshop
|
e386da4132ce781f55000a43b91f81855027047b
|
[
"MIT"
] | 1
|
2018-04-16T07:04:14.000Z
|
2018-04-16T07:04:14.000Z
|
//http://hardwarefun.com/tutorials/url-encoding-in-arduino
String urlEncode(const char* msg)
{
const char *hex = "0123456789abcdef";
String encodedMsg = "";
while (*msg!='\0'){
if( ('a' <= *msg && *msg <= 'z')
|| ('A' <= *msg && *msg <= 'Z')
|| ('0' <= *msg && *msg <= '9') ) {
encodedMsg += *msg;
} else {
encodedMsg += '%';
encodedMsg += hex[*msg >> 4];
encodedMsg += hex[*msg & 15];
}
msg++;
}
return encodedMsg;
}
// http://arduino.stackexchange.com/questions/1013/how-do-i-split-an-incoming-string
String splitStringByIndex(String data, char separator, int index)
{
int found = 0;
int strIndex[] = { 0, -1 };
int maxIndex = data.length()-1;
for(int i=0; i<=maxIndex && found<=index; i++){
if(data.charAt(i)==separator || i==maxIndex){
found++;
strIndex[0] = strIndex[1]+1;
strIndex[1] = (i == maxIndex) ? i+1 : i;
}
}
return found>index ? data.substring(strIndex[0], strIndex[1]) : "";
}
const char *GetValue(const char* value){
char *temp = new char[strlen(value) + 1];
strcpy(temp, value);
return temp;
}
const char *GetStringValue(String value){
int len = value.length() + 1;
char *temp = new char[len];
value.toCharArray(temp, len);
return temp;
}
| 26
| 84
| 0.545118
|
21af24c745d3c900aac7159f9518dcab40ccc15c
| 12,140
|
ino
|
Arduino
|
examples/Thread/Thread.ino
|
solariun/CorePartition
|
cbaff8b0ba4162e394174b0a2b71be6dabb8f7fe
|
[
"MIT"
] | 18
|
2019-08-30T16:28:02.000Z
|
2022-01-23T22:26:08.000Z
|
examples/Thread/Thread.ino
|
solariun/CorePartition
|
cbaff8b0ba4162e394174b0a2b71be6dabb8f7fe
|
[
"MIT"
] | 14
|
2020-06-03T00:08:59.000Z
|
2022-01-28T14:50:34.000Z
|
examples/Thread/Thread.ino
|
solariun/CorePartition
|
cbaff8b0ba4162e394174b0a2b71be6dabb8f7fe
|
[
"MIT"
] | 5
|
2020-01-28T23:38:32.000Z
|
2021-07-13T21:43:02.000Z
|
///
/// @author GUSTAVO CAMPOS
/// @author GUSTAVO CAMPOS
/// @date 28/05/2019 19:44
/// @version <#version#>
///
/// @copyright (c) GUSTAVO CAMPOS, 2019
/// @copyright Licence
///
/*
MIT License
Copyright (c) 2021 Gustavo Campos
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include <assert.h>
#include "Arduino.h"
#include "CorePartition.h"
void SetLocation (uint16_t nY, uint16_t nX)
{
byte szTemp[10];
uint8_t nLen = snprintf ((char*)szTemp, sizeof (szTemp), "\033[%u;%uf", nY, nX);
Serial.write (szTemp, nLen);
}
// workis with 256 colors
void SetColor (const uint8_t nFgColor, const uint8_t nBgColor)
{
byte szTemp[10];
uint8_t nLen = snprintf ((char*)szTemp, sizeof (szTemp), "\033[%u;%um", nFgColor + 30, nBgColor + 40);
Serial.write (szTemp, nLen);
}
void ResetColor ()
{
Serial.print ("\033[0m");
}
void HideCursor ()
{
Serial.print ("\033[?25l");
}
void ShowCursor ()
{
Serial.print ("\033[?25h");
}
void ClearConsole ()
{
Serial.print ("\033[2J");
}
void ReverseColor ()
{
Serial.print ("\033[7m");
}
void Delay (uint64_t nSleep)
{
uint32_t nMomentum = millis ();
// delay (nSleep); return;
do
{
Cpx_Yield ();
} while ((millis () - nMomentum) < nSleep);
}
const uint64_t byteImages[] PROGMEM = {
0x0000000000000000, 0x00180018183c3c18, 0x0000000012246c6c, 0x0036367f367f3636, 0x000c1f301e033e0c, 0x0063660c18336300, 0x006e333b6e1c361c,
0x0000000000030606, 0x00180c0606060c18, 0x00060c1818180c06, 0x0000663cff3c6600, 0x00000c0c3f0c0c00, 0x060c0c0000000000, 0x000000003f000000,
0x000c0c0000000000, 0x000103060c183060, 0x003e676f7b73633e, 0x003f0c0c0c0c0e0c, 0x003f33061c30331e, 0x001e33301c30331e, 0x0078307f33363c38,
0x001e3330301f033f, 0x001e33331f03061c, 0x000c0c0c1830333f, 0x001e33331e33331e, 0x000e18303e33331e, 0x000c0c00000c0c00, 0x060c0c00000c0c00,
0x00180c0603060c18, 0x00003f00003f0000, 0x00060c1830180c06, 0x000c000c1830331e, 0x001e037b7b7b633e, 0x6666667e66663c00, 0x3e66663e66663e00,
0x3c66060606663c00, 0x3e66666666663e00, 0x7e06063e06067e00, 0x0606063e06067e00, 0x3c66760606663c00, 0x6666667e66666600, 0x3c18181818183c00,
0x1c36363030307800, 0x66361e0e1e366600, 0x7e06060606060600, 0xc6c6c6d6feeec600, 0xc6c6e6f6decec600, 0x3c66666666663c00, 0x06063e6666663e00,
0x603c766666663c00, 0x66361e3e66663e00, 0x3c66603c06663c00, 0x18181818185a7e00, 0x7c66666666666600, 0x183c666666666600, 0xc6eefed6c6c6c600,
0xc6c66c386cc6c600, 0x1818183c66666600, 0x7e060c1830607e00, 0x001e06060606061e, 0x00406030180c0603, 0x001e18181818181e, 0x0000000063361c08,
0x003f000000000000, 0x0000000000180c06, 0x7c667c603c000000, 0x3e66663e06060600, 0x3c6606663c000000, 0x7c66667c60606000, 0x3c067e663c000000,
0x0c0c3e0c0c6c3800, 0x3c607c66667c0000, 0x6666663e06060600, 0x3c18181800180000, 0x1c36363030003000, 0x66361e3666060600, 0x1818181818181800,
0xd6d6feeec6000000, 0x6666667e3e000000, 0x3c6666663c000000, 0x06063e66663e0000, 0xf0b03c36363c0000, 0x060666663e000000, 0x3e603c067c000000,
0x1818187e18180000, 0x7c66666666000000, 0x183c666600000000, 0x7cd6d6d6c6000000, 0x663c183c66000000, 0x3c607c6666000000, 0x3c0c18303c000000,
0x00380c0c070c0c38, 0x0c0c0c0c0c0c0c0c, 0x00070c0c380c0c07, 0x0000000000003b6e};
const int byteImagesLen = sizeof (byteImages) / 8;
class TextScroller
{
private:
int nNumberDigits = 15;
uint8_t nOffset = 0;
int nIndex = nNumberDigits * (-1);
uint8_t nSpeed;
uint64_t getLetter (int nIndex, const char* pszMessage, uint16_t nMessageLen)
{
int nCharacter = nIndex > nMessageLen || nIndex < 0 ? ' ' : pszMessage[nIndex];
return getImage (nCharacter - ' ');
}
uint64_t getImage (int nIndex)
{
uint64_t nBuffer = 0xAA;
nIndex = nIndex > byteImagesLen || nIndex < 0 ? 0 : nIndex;
memcpy_P (&nBuffer, byteImages + nIndex, sizeof (uint64_t));
return nBuffer;
}
void printScrollBytes (uint16_t nLocY, uint16_t nLocX, uint16_t nDigit, const uint64_t charLeft, const uint64_t charRight, uint8_t nOffset)
{
int i = 0;
for (i = 0; i < 8; i++)
{
printRow (nLocY, nLocX, nDigit, i, (((uint8_t*)&charLeft)[i] << (8 - nOffset) | ((uint8_t*)&charRight)[i] >> nOffset));
}
}
protected:
virtual void printRow (uint16_t nLocY, uint16_t nLocX, uint16_t nDigit, uint8_t nRowIndex, uint8_t nRow)
{
static char nLine[9] = " ";
int8_t nOffset = 8;
// auto nTmp = nRow;
while (--nOffset >= 0)
{
nLine[7 - nOffset] = ((nRow & 1) != 0) ? '#' : ' ';
nRow >>= 1;
}
SetLocation (nLocY + nRowIndex, nLocX + (nDigit * 9));
Serial.print (nLine);
// Serial.print (nTmp, BIN);
}
public:
TextScroller (int nNumberDigits, uint8_t nSpeed) : nNumberDigits (nNumberDigits), nOffset (0), nSpeed (nSpeed)
{
nIndex = nSpeed == 0 ? 0 : nNumberDigits * (-1);
}
bool show (int nLocY, int nLocX, const char* pszMessage, const uint16_t nMessageLen)
{
uint8_t nCount;
if (nSpeed > 0 && nSpeed % 8 == 0) nSpeed++;
if (nSpeed > 0) do
{
if (nOffset >= 7)
{
nIndex = nIndex + 1 > (int)nMessageLen ? (int)nNumberDigits * (-1) : nIndex + 1;
nOffset = 0;
if ((int)nNumberDigits * (-1) == nIndex) return false;
}
else
{
nOffset = (int)nOffset + (nSpeed % 8);
}
} while (nOffset >= 8);
for (nCount = 0; nCount < nNumberDigits; nCount++)
{
/*
Serial.print (Cpx_GetLastDutyCycle ());
Serial.print (",");
Serial.print (pszMessage [nIndex + 1]);
Serial.print (",");
Serial.print (pszMessage [nIndex]);
Serial.print (":");
*/
printScrollBytes (
nLocY,
nLocX,
nCount,
getLetter (nIndex + 1, pszMessage, nMessageLen),
getLetter (nIndex, pszMessage, nMessageLen),
(uint8_t)nOffset);
nIndex = (int)nIndex + 1;
}
nIndex = (int)nIndex - (nCount - (nSpeed / 8));
return true;
}
};
void ShowRunningThreads ()
{
size_t nCount = 0;
Serial.println ();
Serial.println (F ("Listing all running threads"));
Serial.println (F ("--------------------------------------"));
Serial.println (F ("ID\tStatus\tNice\tStkUsed\tStkMax\tCtx\tUsedMem\tExecTime"));
for (nCount = 0; nCount < Cpx_GetNumberOfActiveThreads (); nCount++)
{
Serial.print (F ("\e[K"));
Serial.print (nCount);
Serial.print (F ("\t"));
Serial.print (Cpx_GetStatusByID (nCount));
Serial.print (F ("\t"));
Serial.print (Cpx_GetNiceByID (nCount));
Serial.print (F ("\t"));
Serial.print (Cpx_GetStackSizeByID (nCount));
Serial.print (F ("\t"));
Serial.print (Cpx_GetMaxStackSizeByID (nCount));
Serial.print (F ("\t"));
Serial.print (Cpx_GetStructContextSize ());
Serial.print (F ("\t"));
Serial.print (Cpx_GetMaxStackSizeByID (nCount) + Cpx_GetStructContextSize ());
Serial.print (F ("\t"));
Serial.print (Cpx_GetLastDutyCycleByID (nCount));
Serial.println ("ms");
Serial.flush ();
}
}
void ThreadTOP (void* pValue)
{
int nCounter = 0;
while (true)
{
ResetColor ();
SetLocation (45, 10);
Serial.println (nCounter++);
ShowRunningThreads ();
Serial.flush ();
Cpx_Yield ();
}
}
void Thread1 (void* pValue)
{
int nSize;
uint32_t nValue = 1;
static char szMessage[25] = "Thread #1: 15.";
nSize = strlen (szMessage);
TextScroller textScroller (15, 8);
while (true)
{
SetColor (1, 0);
nSize = snprintf (szMessage, sizeof (szMessage) - 1, "Thread #1: (%d) .", nValue++);
textScroller.show (5, 7, szMessage, nSize);
Serial.flush ();
Cpx_Yield ();
}
}
void Thread2 (void* pValue)
{
static char szMessage[] = "Thread #2: CorePartition is Universal, working with Windows, Mac, Linux, ARV, ARM, ESP, Tensy, RISC-V....";
TextScroller textScroller (15, 8);
while (true)
{
SetColor (4, 0);
textScroller.show (15, 7, szMessage, sizeof (szMessage) - 1);
Serial.flush ();
Cpx_Yield ();
}
}
void Thread3 (void* pValue)
{
static char szMessage[] = "#3 - This is really a Thread for small processors as well....";
TextScroller textScroller (15, 8);
while (true)
{
SetColor (3, 0);
textScroller.show (25, 10, szMessage, sizeof (szMessage) - 1);
Serial.flush ();
Cpx_Yield ();
}
}
void Thread4 (void* pValue)
{
// uint32_t nValue = 100;
static char szMessage[] = "#4 - Works every where from Windwows, Linux, Mac, to AVR, ARM, RISC-V and ESP";
TextScroller textScroller (15, 8);
while (true)
{
SetColor (2, 0);
textScroller.show (35, 10, szMessage, sizeof (szMessage) - 1);
Serial.flush ();
Cpx_Yield ();
}
}
uint32_t Cpx_GetCurrentTick ()
{
return (uint32_t)millis ();
}
void Cpx_SleepTicks (uint32_t nSleepTime)
{
delay (nSleepTime);
}
void Cpx_StackOverflowHandler ()
{
while (!Serial)
;
Serial.print (F ("[ERROR] - Stack Overflow - Thread #"));
Serial.println (Cpx_GetID ());
Serial.println (F ("--------------------------------------"));
ShowRunningThreads ();
Serial.flush ();
};
void setup ()
{
// Initialize serial and wait for port to open:
Serial.begin (115200);
delay (1000);
while (!Serial)
;
delay (1000);
SetLocation (1, 1);
ResetColor ();
HideCursor ();
ClearConsole ();
Serial.print ("CpxThread ");
Serial.println (CpxVersion);
Serial.println ("");
Serial.println ("Starting up Thread....");
Serial.flush ();
Serial.flush ();
// pinMode (2, OUTPUT);
// pinMode (3, OUTPUT);
// pinMode (4, OUTPUT);
/* To test interrupts jump port 2 and 5 */
// pinMode(nPinOutput, OUTPUT);
// pinMode(nPinInput, INPUT_PULLUP);
// attachInterrupt(digitalPinToInterrupt(nPinInput), Cpx_YieldPreemptive, CHANGE);
// Thread1 ();
assert (Cpx_Start (5));
assert (Cpx_CreateThread (Thread1, NULL, 30 * sizeof (size_t), 100));
assert (Cpx_CreateThread (ThreadTOP, NULL, 20 * sizeof (size_t), 1));
assert (Cpx_CreateThread (Thread2, NULL, 30 * sizeof (size_t), 500));
assert (Cpx_CreateThread (Thread3, NULL, 30 * sizeof (size_t), 900));
assert (Cpx_CreateThread (Thread4, NULL, 30 * sizeof (size_t), 2000));
}
void loop ()
{
Cpx_Join ();
}
| 26.277056
| 147
| 0.617957
|
e29b18be4fc239946b07186dd4a99c7659a799ad
| 3,477
|
ino
|
Arduino
|
KeyboardLights/KeyboardLights.ino
|
DanNixon/ArduinoKeyboardLights
|
5d5fa4feaad8f202077abdefce2fd26e1649240b
|
[
"Apache-2.0"
] | 2
|
2018-11-27T05:37:17.000Z
|
2018-11-27T05:48:18.000Z
|
KeyboardLights/KeyboardLights.ino
|
DanNixon/ArduinoKeyboardLights
|
5d5fa4feaad8f202077abdefce2fd26e1649240b
|
[
"Apache-2.0"
] | null | null | null |
KeyboardLights/KeyboardLights.ino
|
DanNixon/ArduinoKeyboardLights
|
5d5fa4feaad8f202077abdefce2fd26e1649240b
|
[
"Apache-2.0"
] | 1
|
2018-11-27T05:48:19.000Z
|
2018-11-27T05:48:19.000Z
|
#include <MIDI.h>
#include <LedControl.h>
#define TRANS_UP_PIN 7
#define TRANS_DOWN_PIN 6
#define DATA_PIN 4
#define CLOCK_PIN 3
#define LOAD_PIN 2
static const int ledPosition[][2] = { {0,0},
{1,0},
{2,0},
{3,0},
{4,0},
{5,0},
{6,0},
{7,0},
{0,1},
{1,1},
{2,1},
{3,1},
{4,1},
{5,1},
{6,1},
{7,1},
{0,3},
{0,2},
{7,2},
{1,2},
{2,2},
{3,2},
{4,2},
{5,2},
{6,2}
};
static const int midiStartPoints[] = {0, 12, 24, 36, 48, 60, 72, 84, 96};
static const int transposeMin = -4;
static const int transposeMax = 4;
boolean noteStateMatrix[121] = { false };
int transUpSwLast;
int transDownSwLast;
int transpose = 0;
LedControl lc = LedControl(DATA_PIN, CLOCK_PIN, LOAD_PIN, 1);
void transposeUp()
{
if(transpose < transposeMax)
{
transpose++;
transposeDone();
}
}
void transposeDown()
{
if(transpose > transposeMin)
{
transpose--;
transposeDone();
}
}
void transposeDone()
{
int led = 12 + transpose;
for(int i = 0; i < 25; i++)
lc.clearDisplay(0);
setLED(led, true);
delay(50);
refreshLights();
}
void HandleNoteOn(byte channel, byte pitch, byte velocity)
{
noteStateMatrix[pitch] = (velocity > 0);
refreshLights();
}
void refreshLights()
{
int bank = transpose - transposeMin;
int note = midiStartPoints[bank];
for(int i = 0; i < 25; i++)
{
setLED(i, noteStateMatrix[note]);
note++;
}
}
void setLED(int led, boolean lit)
{
int row = ledPosition[led][0];
int col = ledPosition[led][1];
lc.setLed(0, row, col, lit);
}
void setup()
{
//Serial.begin(115200);
MIDI.begin(MIDI_CHANNEL_OMNI);
MIDI.setHandleNoteOn(HandleNoteOn);
MIDI.setHandleNoteOff(HandleNoteOn);
pinMode(13, OUTPUT);
lc.shutdown(0, false);
lc.setIntensity(0, 8);
lc.clearDisplay(0);
pinMode(TRANS_UP_PIN, INPUT);
pinMode(TRANS_DOWN_PIN, INPUT);
digitalWrite(TRANS_UP_PIN, HIGH);
digitalWrite(TRANS_DOWN_PIN, HIGH);
transUpSwLast = digitalRead(TRANS_UP_PIN);
transDownSwLast = digitalRead(TRANS_DOWN_PIN);
digitalWrite(13, LOW);
}
void loop()
{
MIDI.read();
int transDownSwState = digitalRead(TRANS_DOWN_PIN);
if((transDownSwState != transDownSwLast) && (transDownSwState == LOW))
{
transposeDown();
}
transDownSwLast = transDownSwState;
int transUpSwState = digitalRead(TRANS_UP_PIN);
if((transUpSwState != transUpSwLast) && (transUpSwState == LOW))
{
transposeUp();
}
transUpSwLast = transUpSwState;
}
| 26.340909
| 74
| 0.454415
|
90b415acd30acee537ea5d21eb36d2c2d421bf5c
| 2,392
|
ino
|
Arduino
|
main.ino
|
Robonomik/RobonomikBFR-Arduino
|
870eb1d4f07c9034604e358a1644d1fdf9b6c6ab
|
[
"MIT"
] | null | null | null |
main.ino
|
Robonomik/RobonomikBFR-Arduino
|
870eb1d4f07c9034604e358a1644d1fdf9b6c6ab
|
[
"MIT"
] | null | null | null |
main.ino
|
Robonomik/RobonomikBFR-Arduino
|
870eb1d4f07c9034604e358a1644d1fdf9b6c6ab
|
[
"MIT"
] | null | null | null |
#include <SoftwareSerial.h>
SoftwareSerial btSerial(2, 3); // RX, TX
String mess;
int leftUp = 5;
int leftDown = 6;
int rightUp = 9;
int rightDown = 10;
static unsigned long lastTime = 0;
int multPower = 0;
void setup()
{
pinMode(leftUp, OUTPUT);
pinMode(leftDown, OUTPUT);
pinMode(rightUp, OUTPUT);
pinMode(rightDown, OUTPUT);
pinMode(8, OUTPUT);
pinMode(11, OUTPUT);
Serial.begin(9600);
btSerial.begin(9600);
Serial.println("Start");
pinMode(7, OUTPUT);
digitalWrite(7, LOW);
}
void setReverseDir(bool l,bool r){
digitalWrite(8,l);
}
void setPower(int l, int r)
{
int lM = map(l * multPower, 0, 10000, 0, 100);
int rM = map(r * multPower, 0, 10000, 0, 100);
if( lM > 100 || rM > 100) return;
if( lM < 0 || rM < 0) return;
analogWrite(leftUp, lM);
analogWrite(11, lM);
analogWrite(leftDown, lM);
analogWrite(rightUp, rM);
analogWrite(rightDown, rM);
Serial.println(lM);
}
bool onOffSwith = true;
void loop()
{
if (btSerial.available())
{
mess = btSerial.readStringUntil('\n');
}
if (mess.length() > 0)
{
lastTime = millis();
if (mess[0] == 'P')
{
int number = mess.substring(1).toInt();
if(number <= 0 ) number = 0;
if(number > 10000) number = 0;
multPower = number;
}
else if (mess[0] == 'D')
{
int number = mess.substring(1).toInt();
setDirection(number);
}
mess = "";
}
if(millis() - lastTime > 1000){
multPower = 100;
if(onOffSwith) {setPower(10,10); onOffSwith = false;}
else{
setPower(0,0); onOffSwith = true;
}
lastTime = millis();
}
}
void setDirection(int d)
{ switch (d)
{
case -1:
setPower(1, 1);
setReverseDir(false,false);
//Center
break;
case 0:
setPower(100, 100);
setReverseDir(true,false);
//Left
break;
case 1:
setPower(50, 100);
//leftUp
break;
case 2:
setPower(100, 100);
setReverseDir(false,false);
//Up
break;
case 3:
setPower(100, 50);
//RightUp
break;
case 4:
setPower(100, 1);
setReverseDir(false,true);
//Right;
break;
case 5:
//RightDown;
setPower(1, 1);
break;
case 6:
//Down
setPower(1, 1);
setReverseDir(true,true);
break;
case 7:
//DOLLEWY;
setPower(1, 1);
break;
default:
setPower(1, 1);
}
}
| 15.333333
| 57
| 0.573161
|
ffd27968c5531ab6303affe8192cb31655484c8a
| 672
|
ino
|
Arduino
|
examples/Xung/eeprom_write_X/eeprom_write_X.ino
|
buivanxung/project-sim
|
b62fee8c15ab254ff3b001d799a160f788a04c44
|
[
"MIT"
] | null | null | null |
examples/Xung/eeprom_write_X/eeprom_write_X.ino
|
buivanxung/project-sim
|
b62fee8c15ab254ff3b001d799a160f788a04c44
|
[
"MIT"
] | null | null | null |
examples/Xung/eeprom_write_X/eeprom_write_X.ino
|
buivanxung/project-sim
|
b62fee8c15ab254ff3b001d799a160f788a04c44
|
[
"MIT"
] | null | null | null |
/*
* EEPROM Write
*
* Stores values read from analog input 0 into the EEPROM.
* These values will stay in the EEPROM when the board is
* turned off and may be retrieved later by another sketch.
*/
#include <EEPROM.h>
/** the current address in the EEPROM (i.e. which byte we're going to write to next) **/
String seri = "SNS010719V21";
String autho = "7aa4a7d272294f628ee6d51ba8dec55e";
void setup() {
delay(1000);
for(int i = 0; i<1024;i++){
EEPROM.write(i, 0);
}
delay(1000);
for(int i = 0; i< 32;i++){
EEPROM.write(i, autho[i]);
}
delay(1000);
for (int i= 32 ; i< 44; i++){
EEPROM.write(i, seri[i-32]);
}
}
void loop() {
}
| 19.764706
| 88
| 0.623512
|
a5830405dca2d171043cc835b6c513b1c25c296a
| 6,885
|
ino
|
Arduino
|
arduino_scripts/arduino_isr/arduino_isr.ino
|
toopazo/live_ars
|
6fb6ef18ca2e6003df1768e2b1e4147560957fa6
|
[
"MIT"
] | null | null | null |
arduino_scripts/arduino_isr/arduino_isr.ino
|
toopazo/live_ars
|
6fb6ef18ca2e6003df1768e2b1e4147560957fa6
|
[
"MIT"
] | null | null | null |
arduino_scripts/arduino_isr/arduino_isr.ino
|
toopazo/live_ars
|
6fb6ef18ca2e6003df1768e2b1e4147560957fa6
|
[
"MIT"
] | null | null | null |
//timer4 will interrupt at 1Hz
void configure_timer4(void){
cli();//stop interrupts
//set timer4 interrupt at 1Hz
TCCR4A = 0;// set entire TCCR1A register to 0
TCCR4B = 0;// same for TCCR1B
TCNT4 = 0;//initialize counter value to 0
// set compare match register for 1 Hz increments
// OCR4A = 15624/1;// = (16*10^6) / (1*1024) - 1 (must be <65536)
// set compare match register for 10 Hz increments
// OCR4A = 6249;// = (16*10^6) / (10*256) - 1 (must be <65536)
// set compare match register for 100 Hz increments
OCR4A = 624;// = (16*10^6) / (100*256) - 1 (must be <65536)
// set compare match register for 500 Hz increments
// OCR4A = 124;// = (16*10^6) / (500*256) - 1 (must be <65536)
// turn on CTC mode
TCCR4B |= (1 << WGM12);
// Set CS12 and CS10 bits for 1024 prescaler
// TCCR4B |= (1 << CS12) | (1 << CS10);
// Set CS12 for 256 prescaler
TCCR4B |= (1 << CS12);
// enable timer compare interrupt
TIMSK4 |= (1 << OCIE4A);
sei();//allow interrupts
}
void setup(){
Serial.begin(115200);
// Serial.begin(460800);
// configure_timer4();
}
unsigned long tms = 0;
unsigned long ptms = 0;
unsigned long ntms = 0;
unsigned long cnt = 0;
unsigned long pcnt = 0;
const static int adcx_ndata = 100;
int adc0_arr[adcx_ndata];
int adc1_arr[adcx_ndata];
int adc2_arr[adcx_ndata];
int adc3_arr[adcx_ndata];
int adc4_arr[adcx_ndata];
int adc5_arr[adcx_ndata];
int adc6_arr[adcx_ndata];
int adc7_arr[adcx_ndata];
int adc8_arr[adcx_ndata];
int adc9_arr[adcx_ndata];
int adc10_arr[adcx_ndata];
int adc11_arr[adcx_ndata];
int adc12_arr[adcx_ndata];
int adc13_arr[adcx_ndata];
int adc14_arr[adcx_ndata];
int adc15_arr[adcx_ndata];
const static int adcx_nchan = 16;
int adcx_varr[adcx_nchan];
int* get_adcx_arr(int chan){
if(chan == 0){return adc0_arr;}
if(chan == 1){return adc1_arr;}
if(chan == 2){return adc2_arr;}
if(chan == 3){return adc3_arr;}
if(chan == 4){return adc4_arr;}
if(chan == 5){return adc5_arr;}
if(chan == 6){return adc6_arr;}
if(chan == 7){return adc7_arr;}
if(chan == 8){return adc8_arr;}
if(chan == 9){return adc9_arr;}
if(chan == 10){return adc10_arr;}
if(chan == 11){return adc11_arr;}
if(chan == 12){return adc12_arr;}
if(chan == 13){return adc13_arr;}
if(chan == 14){return adc14_arr;}
if(chan == 15){return adc15_arr;}
}
ISR(TIMER4_COMPA_vect){
tms = millis();
cnt ++;
int adc0 = analogRead(A0);
int adc1 = analogRead(A1);
int adc2 = analogRead(A2);
int adc3 = analogRead(A3);
int adc4 = analogRead(A4);
int adc5 = analogRead(A5);
int adc6 = analogRead(A6);
int adc7 = analogRead(A7);
int adc8 = analogRead(A8);
int adc9 = analogRead(A9);
int adc10 = analogRead(A10);
int adc11 = analogRead(A11);
int adc12 = analogRead(A12);
int adc13 = analogRead(A13);
int adc14 = analogRead(A14);
int adc15 = analogRead(A15);
}
void save_data(int val, int arr[], int i){
arr[i] = val;
}
double moving_average(int val, int arr[], int ndata){
//int arr[] = adc0_arr;
// int lastval = arr[ndata-1];
int i = 0;
// Shift array to the left and add val
// [ 0, 1, 2, 3, 4, 5 ] => [ val, 0, 1, 2, 3, 4]
for(i = ndata-1; i >= 1; i--){
arr[i] = arr[i-1];
}
arr[0] = val;
// take average
double newavg = 0;
for(i = 0; i < ndata; i++){
newavg = newavg + (1.0/ndata)*(double)arr[i];
}
return newavg;
}
double static_average(int arr[], int ndata){
double newavg = 0;
int i;
for(i = 0; i < ndata; i++){
newavg = newavg + (double)arr[i]/ndata;
}
return newavg;
}
int num_lows(int arr[], int ndata){
int numlows = 0;
int val0 = 300;
int i;
int val;
for(i = 0; i < ndata; i++){
val = arr[i];
if(val <= val0){
numlows = numlows + 1;
}
}
return numlows;
}
void sense_and_send(void){
if(cnt == adcx_ndata){
// for(int chan=0; chan < adcx_nchan; chan++){
// adcx_varr[chan] = process_data(chan);
// }
send_info();
// send_data(adcx_nchan+1); // Send all at once
cnt = 0;
}
send_data(cnt);
int adc0 = analogRead(A0);
int adc1 = analogRead(A1);
int adc2 = analogRead(A2);
int adc3 = analogRead(A3);
int adc4 = analogRead(A4);
int adc5 = analogRead(A5);
int adc6 = analogRead(A6);
int adc7 = analogRead(A7);
int adc8 = analogRead(A8);
int adc9 = analogRead(A9);
int adc10 = analogRead(A10);
int adc11 = analogRead(A11);
int adc12 = analogRead(A12);
int adc13 = analogRead(A13);
int adc14 = analogRead(A14);
int adc15 = analogRead(A15);
save_data(adc0, adc0_arr, cnt);
save_data(adc1, adc1_arr, cnt);
save_data(adc2, adc2_arr, cnt);
save_data(adc3, adc3_arr, cnt);
save_data(adc4, adc4_arr, cnt);
save_data(adc5, adc5_arr, cnt);
save_data(adc6, adc6_arr, cnt);
save_data(adc7, adc7_arr, cnt);
save_data(adc8, adc8_arr, cnt);
save_data(adc9, adc9_arr, cnt);
save_data(adc10, adc10_arr, cnt);
save_data(adc11, adc11_arr, cnt);
save_data(adc12, adc12_arr, cnt);
save_data(adc13, adc13_arr, cnt);
save_data(adc14, adc14_arr, cnt);
save_data(adc15, adc15_arr, cnt);
//send_info();
//Serial.println("");
//Serial.flush();
cnt ++;
}
int process_data(int chan){
int *varr = get_adcx_arr(chan);
int res;
if(chan < 8){
res = num_lows(varr, adcx_ndata);
}
else{
res = (int)static_average(varr, adcx_ndata);
}
return res;
}
void send_data(int chan){
if(chan < adcx_nchan){
adcx_varr[chan] = process_data(chan);
//Serial.print(",");
Serial.print(adcx_varr[chan]);
Serial.print(",");
}
if(chan == adcx_nchan){
Serial.println("");
}
// Send all at once
// if(chan == adcx_nchan+1){
// for(int chan = 0; chan < adcx_nchan; chan++){
// Serial.print(adcx_varr[chan]);
// Serial.print(",");
// }
// Serial.println("");
// }
}
void send_info(void){
Serial.print(cnt);
Serial.print(",");
Serial.print(tms); //, 3);
Serial.print(",");
Serial.print((double)tms/1000, 3); //, 3);
Serial.print(",");
Serial.print(millis()-tms); //, 3);
Serial.print(": ");
//Serial.println("");
//Serial.flush();
}
// the loop routine runs over and over again forever:
void loop() {
// if (cnt == pcnt){
// // just wait for next samples
// }
// else{
// if (tms <= 20000){
// send_info();
// }
// if (cnt != pcnt + 1){
// Serial.println("Errror: (cnt != pcnt + 1)");
// while(1){}
// }
// pcnt = cnt;
// ptms = tms;
// }
tms = millis();
if( tms >= ntms ){
if (tms <= 20000){
sense_and_send();
int tmscnt = (tms % 1000)/10; // (19980 % 1000)/10 = 98
if(tmscnt == cnt){
send_info();
Serial.println(", tmscnt");
while(1){};
}
}
// ntms = ntms + 10;
ntms = ntms + 10;
}
}
| 23.989547
| 67
| 0.597676
|
fc313f6a537f91ddc2b33a40a2ae57bd8ec75231
| 912
|
ino
|
Arduino
|
examples/BleepingFirmwareManager/BleepingFirmwareManager.ino
|
MClarkDev/BleepingLibrary
|
8dbd1d8273803d34f34fc4aa23f271fdeaf2e2d3
|
[
"Apache-2.0"
] | 1
|
2022-03-05T03:39:22.000Z
|
2022-03-05T03:39:22.000Z
|
examples/BleepingFirmwareManager/BleepingFirmwareManager.ino
|
MClarkDev/BleepingLibrary
|
8dbd1d8273803d34f34fc4aa23f271fdeaf2e2d3
|
[
"Apache-2.0"
] | null | null | null |
examples/BleepingFirmwareManager/BleepingFirmwareManager.ino
|
MClarkDev/BleepingLibrary
|
8dbd1d8273803d34f34fc4aa23f271fdeaf2e2d3
|
[
"Apache-2.0"
] | null | null | null |
/**
BleepingFirmwareManager
An example ESP32 sketch using the Bleep App and Library
Read more in the Getting Started guide.
https://github.com/MClarkDev/BleepingLibrary/blob/master/GettingStarted.md
*/
#define OTA_APPNAME "BleepingFirmwareManager"
#define OTA_VERSION 1
#include "BleepingLibrary.h"
BleepingLibrary bLib;
void setup() {
// Initialize
int boots = bLib.init();
ESP_LOGI(_BLib, "Boots: %d", boots);
// Setup BLE server
BleepingServer* server = bLib.getServer();
server->startServer();
// Enable management from BLE
bLib.enableUpdater(OTA_APPNAME, OTA_VERSION);
bLib.enableUpdateManager();
/**
Implement your code below!
*/
ESP_LOGI(_BLib, "Now running my Bleeping App!");
ESP_LOGI(_BLib, "Setup mode is still running!");
}
void loop() {
delay(1000);
ESP_LOGI(_BLib, "Now running my Bleeping App!");
}
| 21.714286
| 78
| 0.679825
|
8ef50cc8ef219e50eb9fcb9320d7a489912365df
| 901
|
ino
|
Arduino
|
anyio/arduino/firmware/mouse/mouse.ino
|
aptanet/anyio
|
1f36e5f53ca99b014898ee9a3d35e970ebf9a677
|
[
"MIT"
] | 20
|
2015-02-26T14:05:01.000Z
|
2021-05-17T17:39:19.000Z
|
anyio/arduino/firmware/mouse/mouse.ino
|
aptanet/anyio
|
1f36e5f53ca99b014898ee9a3d35e970ebf9a677
|
[
"MIT"
] | 17
|
2015-04-15T17:50:31.000Z
|
2018-10-28T20:57:16.000Z
|
anyio/arduino/firmware/mouse/mouse.ino
|
aptanet/anyio
|
1f36e5f53ca99b014898ee9a3d35e970ebf9a677
|
[
"MIT"
] | 13
|
2015-05-04T20:44:15.000Z
|
2020-11-04T09:53:15.000Z
|
/* mouse.ino 27/07/2014 D.J.Whale
*
* Move a mouse by pressing 4 direction buttons
*/
#define BUTTON_LEFT 2
#define BUTTON_RIGHT 3
#define BUTTON_UP 4
#define BUTTON_DOWN 5
#define SENSITIVITY 1
#define RATE 10
void setup()
{
pinMode(BUTTON_LEFT, INPUT);
pinMode(BUTTON_RIGHT, INPUT);
pinMode(BUTTON_UP, INPUT);
pinMode(BUTTON_DOWN, INPUT);
}
void loop()
{
if (digitalRead(BUTTON_LEFT) == 0)
{
horizontal(-SENSITIVITY);
delay(RATE);
}
else if (digitalRead(BUTTON_RIGHT) == 0)
{
horizontal(SENSITIVITY);
delay(RATE);
}
else if (digitalRead(BUTTON_UP) == 0)
{
vertical(-SENSITIVITY);
delay(RATE);
}
else if (digitalRead(BUTTON_DOWN) == 0)
{
vertical(SENSITIVITY);
delay(RATE);
}
}
void vertical(int amount)
{
Mouse.move(0, amount, 0);
}
void horizontal(int amount)
{
Mouse.move(amount, 0, 0);
}
/* END */
| 15.016667
| 47
| 0.6404
|
b80fa6f9de8b80b97c8aa69324e191d3ca7c58d8
| 902
|
ino
|
Arduino
|
RTC_Alarm/RTC_Alarm.ino
|
ndrohith09/arduino
|
a2c04e15789dd58a37559cb7ed0cee4b39d12bc4
|
[
"MIT"
] | 8
|
2020-10-25T14:18:16.000Z
|
2022-03-07T10:25:15.000Z
|
RTC_Alarm/RTC_Alarm.ino
|
ndrohith09/arduino
|
a2c04e15789dd58a37559cb7ed0cee4b39d12bc4
|
[
"MIT"
] | null | null | null |
RTC_Alarm/RTC_Alarm.ino
|
ndrohith09/arduino
|
a2c04e15789dd58a37559cb7ed0cee4b39d12bc4
|
[
"MIT"
] | 3
|
2020-10-26T12:42:50.000Z
|
2022-02-06T15:11:36.000Z
|
#include<D53231.h>
D53231 rtc(SDA, SCL);
TIme t;
void setup() {
Serial.begin(115200);
rtc.begin();
rtc.setDOW(WEDNESDAY);
rtc.setTime(12, 0, 0);
rtc.setDate(1, 1, 2020);
pinMode(13, OUTPUT);
}
void loop() {
t = rtc.getTime();
Serial.print("Date");
Serial.print(t.date, DEC);
Serial.print("/");
Serial.print(t.mon, DEC);
Serial.print("/");
Serial.print(t.year, DEC);
Serial.println();
//send days of week and time
Serial.print("Day of Week");
Serial.print(t.dow, DEC);
Serial.print();
Serial.print("Time");
Serial.print(t.hour, DEC);
Serial.print(":");
Serial.print(t.min, DEC);
Serial.print(":");
Serial.print(t.sec, DEC);
Serial.println();
Serial.println("------------------------------");
delay(1000);
if (t.hour == 12 && t.min == 0 && t.sec == 10) {
digitalWrite(13, HIGH);
delay(5000);
}
}
| 22
| 52
| 0.554324
|
11010132c8278dbec1487f0f33b7f3fc1d1c5cac
| 4,709
|
ino
|
Arduino
|
Arduino/wifi_vault/wifi_vault.ino
|
dimityrivanov/WifiVault
|
70a9d1127cfb184568432d8901c79345aa4e5061
|
[
"MIT"
] | 9
|
2019-07-30T11:27:32.000Z
|
2019-11-04T15:36:52.000Z
|
Arduino/wifi_vault/wifi_vault.ino
|
mitko9000/WifiVault
|
70a9d1127cfb184568432d8901c79345aa4e5061
|
[
"MIT"
] | null | null | null |
Arduino/wifi_vault/wifi_vault.ino
|
mitko9000/WifiVault
|
70a9d1127cfb184568432d8901c79345aa4e5061
|
[
"MIT"
] | null | null | null |
#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>
#include <ESP8266SSDP.h>
#include <WiFiManager.h>
#include <DNSServer.h>
#include "EEPROMManager.h"
#include "DebugSerial.h"
#include "BeamRequest.cpp"
#include <ArduinoJson.h>
#include <stdlib.h>
EEPROMManager eepromManager;
DebugSerial debugSerial;
const char* www_username = "<set here>";
const char* www_password = "<set here>";
JsonObject mLastRedJsonObject;
StaticJsonDocument<200> doc;
ESP8266WebServer HTTP(1900);
void setup() {
Serial.begin(9600);
WiFiManager wifiManager;
wifiManager.autoConnect("WifiVault");
config_rest_server_routing();
}
void request_authorization() {
if (!HTTP.authenticate(www_username, www_password)) {
return HTTP.requestAuthentication();
}
}
boolean checkForKey(const char* key) {
if (!mLastRedJsonObject.containsKey(key)) {
debugSerial.printToSerial("wrong json format for request!!!");
HTTP.send(400, "application/json", "{\"success\" : false}");
return false;
}
return true;
}
void parseRequestBody() {
request_authorization();
doc.clear();
String post_body = HTTP.arg("plain");
//Serial.println(post_body);
DeserializationError error = deserializeJson(doc, post_body);
if (error) {
debugSerial.printToSerial("error in parsin json body");
HTTP.send(400, "application/json", "{\"success\" : false}");
}
mLastRedJsonObject = doc.as<JsonObject>();
}
void get_psw() {
parseRequestBody();
if (!checkForKey("addr")) {
return;
}
const int addr = mLastRedJsonObject["addr"];
PasswordObject obj = eepromManager.readEEPROMObject(addr);
StaticJsonDocument<100> jsonResponseDoc;
jsonResponseDoc["addr"] = addr;
jsonResponseDoc["key"] = obj.name;
jsonResponseDoc["value"] = obj.password;
char JSONmessageBuffer[100];
serializeJsonPretty(jsonResponseDoc, JSONmessageBuffer);
HTTP.send(200, "application/json", JSONmessageBuffer);
}
void post_psw() {
parseRequestBody();
if (!checkForKey("key")) {
return;
}
debugSerial.printToSerial("Searching for empty address:");
int address_value = eepromManager.findEmptyAddress();
if (address_value != eepromManager.NULL_ADDRESS) {
PasswordObject customVar;
strlcpy(customVar.name, mLastRedJsonObject["key"] | "", sizeof(customVar.name));
strlcpy(customVar.password, mLastRedJsonObject["value"] | "", sizeof(customVar.password));
eepromManager.writeEEPROMObject(address_value, customVar);
HTTP.send(200, "application/json", "{\"success\" : true}");
} else {
debugSerial.printToSerial("No more space in EEPROM!!!");
HTTP.send(400, "application/json", "{\"success\" : false}");
}
}
void sendDataSerial(const char* text) {
Serial.println(text);
delay(200);
Serial.flush();
}
void beam_details() {
parseRequestBody();
if (!checkForKey("user")) {
return;
}
BeamRequest beam;
beam.username = mLastRedJsonObject["user"];
beam.password = mLastRedJsonObject["pass"];
sendDataSerial(beam.username);
sendDataSerial(beam.password);
HTTP.send(200, "application/json", "{\"success\" : true}");
}
void delete_psw() {
parseRequestBody();
if (!checkForKey("addr")) {
return;
}
//if everything is fine we will process the request here
eepromManager.clearEEPROMAddr(mLastRedJsonObject["addr"]);
HTTP.send(200, "application/json", "{\"success\" : true}");
}
void config_rest_server_routing() {
if (WiFi.waitForConnectResult() == WL_CONNECTED) {
debugSerial.printToSerial("Starting HTTP...\n");
HTTP.on("/index.html", HTTP_GET, []() {
HTTP.send(200, "text/plain", "{\"deviceID\":\"<set here>\"}");
});
HTTP.on("/description.xml", HTTP_GET, []() {
SSDP.schema(HTTP.client());
});
HTTP.on("/get_psw", HTTP_POST, get_psw);
HTTP.on("/psw", HTTP_POST, post_psw);
HTTP.on("/del_psw", HTTP_POST, delete_psw);
HTTP.on("/beam", HTTP_POST, beam_details);
HTTP.begin();
debugSerial.printToSerial("Starting SSDP...\n");
SSDP.setSchemaURL("description.xml");
SSDP.setHTTPPort(1900);
SSDP.setName("WiFi Vault");
SSDP.setSerialNumber("<set here>");
SSDP.setURL("index.html");
SSDP.setModelName("WiFi Vault");
SSDP.setModelNumber("<set here>");
SSDP.setModelURL("http://www.google.bg");
SSDP.setManufacturer("Dimitar Ivanov");
SSDP.setManufacturerURL("http://www.google.bg");
//SSDP.setDeviceType("upnp:rootdevice");
SSDP.setDeviceType("urn:schemas-upnp-org:device:WifiVault:1");
SSDP.begin();
debugSerial.printToSerial("Ready!\n");
} else {
debugSerial.printToSerial("WiFi Failed\n");
while (1) {
delay(100);
}
}
}
void loop() {
HTTP.handleClient();
delay(1);
}
| 24.273196
| 94
| 0.682735
|
f806f1fd6f59bae93c1efcc6babd2b1c134440aa
| 12,138
|
ino
|
Arduino
|
Sensor data acquisition from Electrical Kart - Arduino MEGA/Final Assembly/Final Assembly.ino
|
dimitrov9/my-projects
|
dfd6b38b24a1faf179517e74e8b466962fe342c7
|
[
"MIT"
] | null | null | null |
Sensor data acquisition from Electrical Kart - Arduino MEGA/Final Assembly/Final Assembly.ino
|
dimitrov9/my-projects
|
dfd6b38b24a1faf179517e74e8b466962fe342c7
|
[
"MIT"
] | null | null | null |
Sensor data acquisition from Electrical Kart - Arduino MEGA/Final Assembly/Final Assembly.ino
|
dimitrov9/my-projects
|
dfd6b38b24a1faf179517e74e8b466962fe342c7
|
[
"MIT"
] | null | null | null |
/* boolean connectESP8266_toInternet(String wifiNetworkName,String wifiNetworkPassword, int port); Set your home wifi network SSID and PASSWORD (Put this function on start of void setup)
*
* boolean createLocalESP8266_wifiServer(String wifiNetworkName,String wifiNetworkPassword, int port, int mode); Use this function to create an ESP8266 wifi local network
* set port to 80
* set mode=2 to use ESP8266 only as access point
* set mode=3 to use ESP8266 as access point and internet station.
*
* bool esp8266_setIP(byte a1, byte a2, byte a3, byte a4); set ESP8266 local IP. Use this function after connectESP8266_toInternet function
*
* ========= Virtuino general methods
* void vDigitalMemoryWrite(int digitalMemoryIndex, int value) write a value to a Virtuino digital memory (digitalMemoryIndex=0..31, value range = 0 or 1)
* int vDigitalMemoryRead(int digitalMemoryIndex) read the value of a Virtuino digital memory (digitalMemoryIndex=0..31, returned value range = 0 or 1)
* void vMemoryWrite(int memoryIndex, float value); write a value to Virtuino memory (memoryIndex=0..31, value range as float value)
* float vMemoryRead(int memoryIndex); read a value of Virtuino memory (memoryIndex=0..31, returned a float value
* run(); neccesary command to communicate with Virtuino android app (on start of void loop)
* int getPinValue(int pin); read the value of a Pin. Usefull to read the value of a PWM pin
* void vDelay(long milliseconds); Pauses the program (without block communication) for the amount of time (in miliseconds) specified as parameter
* void vDelay(long milliseconds); Pauses the program (without block communication) for the amount of time (in miliseconds) specified as parameter
* void clearTextBuffer(); Clear the text received text buffer
* int textAvailable(); Check if there is text in the received buffer
* String getText(byte ID); Read the text from Virtuino app
* void sendText(byte ID, String text); Send text to Virtuino app
*/
#include "VirtuinoEsp8266_WebServer.h"
#include <OneWire.h>
#include <DallasTemperature.h>
#include <TinyGPS++.h>
#define trigPin1 8
#define echoPin1 9
#define trigPin2 12
#define echoPin2 13
float duration, distance, UltraSensor1, UltraSensor2, t1, t2, vout, vin = 0.0;
float R1 = 30000.0;
float R2 = 7500.0;
int analogInput = A1;
int val = 0;
TinyGPSPlus gps;
volatile int cnt = 0;
unsigned long rpm, speed_val = 0;
unsigned long timeold, temp = 0;
// temperaturni senzori
int temp_sensor1 = 5; //- pinovi na koi sa povrzani
int temp_sensor2 = 6;
OneWire oneWirePin1(temp_sensor1);
OneWire oneWirePin2(temp_sensor2);
//temp za baterija
DallasTemperature sensor1(&oneWirePin1);
//temp za motor
DallasTemperature sensor2(&oneWirePin2);
VirtuinoEsp8266_WebServer virtuino(Serial2,115200);
// Connect the ESP01 module to Arduino Mega - Due Serial1 port as the plan below
// http://iliaslamprou.mysch.gr/virtuino/esp8266_arduino_mega_connection_plan.png
// Arduino Mega settings -> Open VirtuinoEsp8266_WebServer file on the virtuino library folder -> disable the line: #define ESP8266_USE_SOFTWARE_SERIAL
// Arduino Due settings -> 1.Open VirtuinoBluetooth.h on the virtuino library folder -> disable the line: #define BLUETOOTH_USE_SOFTWARE_SERIAL
// -> 2.Open VirtuinoEsp8266_WebServer file on the virtuino library folder -> disable the line: #define ESP8266_USE_SOFTWARE_SERIAL
void setup()
{
virtuino.DEBUG=true; // set this value TRUE to enable the serial monitor status.It is neccesary to get your esp8266 local ip
Serial.begin(9600);
Serial2.begin(115200);
// Enable this line only if DEBUG=true
virtuino.createLocalESP8266_wifiServer("ESP","ESPmodulwifi",80,2);
//virtuino.connectESP8266_toInternet("username","password",8000); // Set your home wifi router SSID and PASSWORD. ESP8266 will connect to Internet. Port=80
//virtuino.esp8266_setIP(192,168,0,100); // Set a local ip. Forward port 80 to this IP on your router
//virtuino.createLocalESP8266_wifiServer("ESP8266 NETWORK NAME","PASSWORD",80,2); //Enable this line to create a wifi local netrork using ESP8266 as access point
//Do not use less than eight characters for the password. Port=80 //Default access point ESP8266 ip=192.168.4.1.
virtuino.password="1234"; // Set a password to your web server for more protection
// avoid special characters like ! $ = @ # % & * on your password. Use only numbers or text characters
Serial1.begin(9600);
sensor1.begin();
sensor2.begin();
pinMode(analogInput, INPUT);
pinMode(trigPin1, OUTPUT);
pinMode(echoPin1, INPUT);
pinMode(trigPin2, OUTPUT);
pinMode(echoPin2, INPUT);
}
void loop(){
virtuino.run(); // necessary command to communicate with Virtuino android app
get_temp();
Serial.println(arduino.waitForResponse(
// Temperature sensors
Serial.print("Temperature on Sensor 1 is: ");
Serial.print(sensor1.getTempCByIndex(0)); // Why "byIndex"? You can have more than one IC on the same bus. 0 refers to the first IC on the wire
Serial.print(" ");
Serial.print("Sensor 2 is: ");
Serial.print(sensor2.getTempCByIndex(0));
Serial.println();
// write to memory
virtuino.vMemoryWrite(0,sensor1.getTempCByIndex(0));
virtuino.vMemoryWrite(1,sensor2.getTempCByIndex(0));
virtuino.vDelay(2000); //Update value every 2 sec
// Sonar sensors
SonarSensor(trigPin1, echoPin1); // look bellow to find the difinition of the SonarSensor function
UltraSensor1 = distance; // store the distance in the first variable
SonarSensor(trigPin2,echoPin2); // call the SonarSensor function again with the second sensor pins
UltraSensor2 = distance; // store the new distance in the second variable
delay(2000);
// display the distances on the serial monitor for the first sensor
//----------------------------------------------------------------------------------------------------------------------
Serial.print("distance measured by the first sensor: ");
if (UltraSensor1 >= 400 || UltraSensor1 <= 2){
Serial.println("Out of range");
}
else {
Serial.print(UltraSensor1);
Serial.println(" cm");
virtuino.vMemoryWrite(2,UltraSensor1);
}
//----------------------------------------------------------------------------------------------------------------------
//display the distance on the serial monitor for the second sensor
//----------------------------------------------------------------------------------------------------------------------
Serial.print("distance measured by the second sensor: ");
if (UltraSensor2 >= 400 || UltraSensor2 <= 2){
Serial.println("Out of range");
}
else {
Serial.print(UltraSensor2);
Serial.println(" cm");
virtuino.vMemoryWrite(3,UltraSensor2);
}
// Get voltage
val = analogRead(analogInput);
vout = (val * 5.0) / 1024.0;
vin = vout / (R2/(R1+R2));
//Serial.print("INPUT V= ");
//Serial.println(vin,2);
// write to memory
virtuino.vMemoryWrite(4,vin);
virtuino.vDelay(2000); //Update value every 2 sec
// GPS
while(Serial1.available())//While there are characters to come from the GPS
{
gps.encode(Serial1.read());//This feeds the serial NMEA data into the library one char at a time
}
if(gps.location.isUpdated())//This will pretty much be fired all the time anyway but will at least reduce it to only after a package of NMEA data comes in
{
//Get the latest info from the gps object which it derived from the data sent by the GPS unit
//Serial.println("Satellite Count:");
//Serial.println(gps.satellites.value());
//Serial.println("Latitude:");
//Serial.println(gps.location.lat(), 6);
//Serial.println("Longitude:");
//Serial.println(gps.location.lng(), 6);
//Serial.println("Speed KMH:");
//Serial.println(gps.speed.kmph());
//Serial.println("Altitude meters:");
//Serial.println(gps.altitude.meters());
//Serial.println("Time:");
//Serial.print(gps.time.hour() + 2);
//Serial.print(":");
//Serial.print(gps.time.minute());
//Serial.print(":");
//Serial.println(gps.time.second());
//Serial.println("Date:");
//Serial.print(gps.date.day());
//Serial.print(".");
//Serial.print(gps.date.month());
//Serial.print(".");
//Serial.print(gps.date.year());
//Serial.println("");
double latitude = gps.location.lat();
double longitude = gps.location.lng();
int latDeg = (int)latitude;
int lngDeg = (int)longitude;
int latMin = (int)((latitude - latDeg)*100);
int lngMin = (int)((longitude - lngDeg)*100);
double latSec = (((latitude - latDeg)*100) - latMin)*100;
double lngSec = (((longitude - lngDeg)*100) - lngMin )*100;
// write to memory
virtuino.vMemoryWrite(5, gps.satellites.value());
virtuino.vMemoryWrite(6, latDeg);
virtuino.vMemoryWrite(7, lngDeg);
virtuino.vMemoryWrite(8, latMin);
virtuino.vMemoryWrite(9, lngMin);
virtuino.vMemoryWrite(10, latSec);
virtuino.vMemoryWrite(11, lngSec);
virtuino.vMemoryWrite(12, gps.speed.kmph());
virtuino.vMemoryWrite(13, gps.altitude.meters());
// virtuino.vMemoryWrite(14, gps.time.hour() + 2);
// virtuino.vMemoryWrite(15, gps.time.minute());
// virtuino.vMemoryWrite(16, gps.time.second());
// virtuino.vMemoryWrite(17, gps.date.day());
// virtuino.vMemoryWrite(18, gps.date.month());
// virtuino.vMemoryWrite(19, gps.date.year());
}
}
void get_temp(){
sensor1.requestTemperatures(); // Send the command to get temperatures
sensor2.requestTemperatures();
t1 = sensor1.getTempCByIndex(0); // Why "byIndex"? You can have more than one IC on the same bus. 0 refers to the first IC on the wire
t2 = sensor2.getTempCByIndex(0);
}
void SonarSensor(int trigPinSensor,int echoPinSensor)//it takes the trigPIN and the echoPIN
{
//START SonarSensor FUNCTION
//generate the ultrasonic wave
//----------------------------------------------------------------------------------------------------------------------
digitalWrite(trigPinSensor, LOW);// put trigpin LOW
delayMicroseconds(2);// wait 2 microseconds
digitalWrite(trigPinSensor, HIGH);// switch trigpin HIGH
delayMicroseconds(10); // wait 10 microseconds
digitalWrite(trigPinSensor, LOW);// turn it LOW again
//----------------------------------------------------------------------------------------------------------------------
//read the distance
//----------------------------------------------------------------------------------------------------------------------
duration = pulseIn(echoPinSensor, HIGH);//pulseIn funtion will return the time on how much the configured pin remain the level HIGH or LOW; in this case it will return how much time echoPinSensor stay HIGH
distance= (duration/2) * 0.0343; // first we have to divide the duration by two
}// END SonarSensor FUNCTION
| 49.745902
| 281
| 0.601087
|
8f0fb361471d420b059db023be659b9e175d103d
| 4,997
|
ino
|
Arduino
|
Arduino/setup.ino
|
npmcdn-to-unpkg-bot/Micromouse
|
abaa369a43975103d677624bd848b2f1ba103fc9
|
[
"CC-BY-3.0"
] | 26
|
2015-01-14T00:02:13.000Z
|
2020-10-17T12:53:09.000Z
|
Arduino/setup.ino
|
npmcdn-to-unpkg-bot/Micromouse
|
abaa369a43975103d677624bd848b2f1ba103fc9
|
[
"CC-BY-3.0"
] | null | null | null |
Arduino/setup.ino
|
npmcdn-to-unpkg-bot/Micromouse
|
abaa369a43975103d677624bd848b2f1ba103fc9
|
[
"CC-BY-3.0"
] | 13
|
2015-04-04T17:16:04.000Z
|
2022-01-18T14:21:16.000Z
|
/*
1 = SENSORS
2 = ROTATE
3 = FORWARD
*/
#define DEBUG 0
/*
1 = ENABLED
2 = SENSORS
4 = FLOODFILL
*/
#define DEBUG_PRINT 0 //3
// Define program constants
#define UNDEFINED -10
#define LENGTH 9
#define AREA 81
#define AREA_WALLS 9 * (9 - 1) - 1
// Action constants
#define ACTION_MOVE 1
#define ACTION_ROTATE 2
// Motor specific
#define MODE_TYPE 8
#define REVS_FULL 1600 // 1600 steps in one full wheel revolution
#define REVS_SQUARE 1665 // No of steps to move a square (~17.5 cm) (1641) (1684) (18cm) (1664)
//With 1684 moving ahead by 1.5cm
// 2756 seems to give perfect turns
#define STEPS_360 2757 // No of steps to rotate 360 degrees (2804) (2800) (2739)
#define DEGREE_STEPS STEPS_360 / float(360.0) // How many steps per degree
// Sensor specific
#define NUM_READS 50
#define FRONT A2
#define FRONT_LEFT A0
#define FRONT_RIGHT A1
// Digital inputs
#define SWITCH 13
// Digital outputs
#define DIR_L 39 // Grey
#define STEP_L 9 // Yellow (marked)
#define MS1_L 43 // Blue
#define MS2_L 45 // Green
#define SLEEP_L 47 // White
#define RESET_L 49 // Brown
#define ENABLE_L 51 // Orange
#define PFD_L 53 // Purple
//2nd Stepper Motor
#define DIR_R 38 // Grey
#define STEP_R 8 // Yellow
#define MS1_R 42 // Blue
#define MS2_R 44 // Green
#define SLEEP_R 46 // White
#define RESET_R 48 // Brown
#define ENABLE_R 50 // Orange
#define PFD_R 52 // Purple
// Memory (position, direction etc)
int lastCol = 0;
int lastRow = 0;
int curCol = 0;
int curRow = 0;
int corner = UNDEFINED;
int turns = 0;
int direction = 0;
int lastDirection = 0;
int lastAction = 0;
float speed = 980.0;
void setup() {
// Setup serial out
Serial.begin(9600);
// Initialise pin modes
pinMode(SWITCH, INPUT);
// Initialize motors
initializeFloodfill();
initializeSensors();
initializeMotors();
// Sense walls in north straight away
boolean north, east, south, west;
sense(north, east, south, west);
// Attach start button to interrupt handler
attachInterrupt(SWITCH, toggle, CHANGE);
}
// Interrupt handler - Turns on/off motor drivers when switch is changed
static boolean enabled = false;
static unsigned long last_enable_time = 0;
void toggle() {
unsigned long enable_time = millis();
// If interrupts come faster than 200ms, assume it's a bounce and ignore
if(enable_time - last_enable_time > 200) {
enabled = digitalRead(SWITCH);
print("ENABLED? " + String(enabled ? "YES" : "NO"));
sleepDrivers( !enabled );
//delay(1000);
}
last_enable_time = enable_time;
}
void loop() {
// Move the motors and if currently moving... return
if(!enabled || process()) { return; }
if(DEBUG) {
switch(DEBUG) {
case 1: debug_sensors(); break;
case 2: turn(); break;
case 3: forward(); break;
}
return;
}
int nextVal = AREA, nextRow, nextCol;
boolean north, east, south, west;
// If we'eve reached the center of the maze...
if(getFloodfillValue(curRow, curCol) == 0) {
enabled = false; return;
}
// If we just rotated... sense first to update floodfill
if(lastAction == 2 || corner == UNDEFINED) {
sense(north, east, south, west);
}
if(corner == UNDEFINED) {
print("NO CORNER KNOWN.... MOVE FORWARD FOR NOW");
nextRow = curRow + 1; nextCol = curCol;
moveTo(nextRow, nextCol);
return;
}
// Start group
startGroup("PROCESSING NEXT MOVE");
// Look al all 4 sides to the current cell and determine the lowest floodfill value...
for(int dir = 0; dir < 4; dir++) {
boolean hasWall = wallExists(curRow, curCol, dir);
int row = curRow, col = curCol;
getAdjacentWall(row, col, dir);
int val = getFloodfillValue(row, col);
if(!hasWall && (val == nextVal && dir == direction || val < nextVal)) {
nextRow = row;
NextCol = col;
nextVal = val;
}
}
print(
"MOVING TO (" + String(nextRow) + "/" + String(nextCol) + ") WITH VALUE " + nextVal +
" FROM (" + String(curRow) + "/" + String(curCol) + ")"
);
// Determine the new direction
int newDirection = curCol == nextCol ? ( curRow < nextRow ? 0 : 2 ) :
corner == 3 ? ( curCol < nextCol ? 1 : 3 ) : ( curCol < nextCol ? 3 : 1 );
// If we need to rotate... go!
if(newDirection != direction) {
startGroup("ROTATION");
print("NEW DIRECTION IS " + String(newDirection));
// Keep track of the number of turns and set direction
turns -= direction - newDirection;
rotate(abs(direction - newDirection) * 90, direction - newDirection > 0);
direction = newDirection;
endGroup();
}
// No rotation? Sense and move
else {
// Sense the forward blocks surrounding area using sensors
sense(north, east, south, west);
// Check for a dead end (but make sure it isn't the center!)
if(getFloodfillValue(nextRow, nextCol) < 1 || (north + east + south + west) < 3) {
moveTo(nextRow, nextCol);
}
else {
print("DEAD END. DON'T MOVE.");
}
}
endGroup();
}
boolean process() {
// Continually process sensor values
processSensors();
// Process motors
return processMotors();
}
| 23.350467
| 95
| 0.664799
|
200cb0d991523e7e0b962bd4e30b25a77dd4b7ef
| 4,821
|
ino
|
Arduino
|
BitReceiver_withCMDCode_MotorDriving/BitReceiver_withCMDCode_MotorDriving.ino
|
hoilett/Bit-the-RoboDawg
|
3a651c7cd3836c38dc9b7366c3d1164e06d8803f
|
[
"MIT"
] | 3
|
2016-05-09T22:07:16.000Z
|
2016-05-25T00:20:54.000Z
|
BitReceiver_withCMDCode_MotorDriving/BitReceiver_withCMDCode_MotorDriving.ino
|
hoilett/Bit-the-RoboDawg
|
3a651c7cd3836c38dc9b7366c3d1164e06d8803f
|
[
"MIT"
] | null | null | null |
BitReceiver_withCMDCode_MotorDriving/BitReceiver_withCMDCode_MotorDriving.ino
|
hoilett/Bit-the-RoboDawg
|
3a651c7cd3836c38dc9b7366c3d1164e06d8803f
|
[
"MIT"
] | null | null | null |
/*
* Shadman Jubaer and Orlando Hoilett
*
* Project Title: Bit the RoboCar
*
* Description
* We created a remote controlled car using two nRF24L01 RF
* transceiver modules. An Arduino reads the directeion values
* from a joystick and sends the instructions to another Arduino
* to control a robot chassis.
*
*/
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#include <RF24_config.h>
int l1_motor = 10;
int l2_motor = 9;
int r1_motor = 6;
int r2_motor = 5;
int messageLength = 12;
int msg[1];
RF24 radio(7,8);
const uint64_t pipe = 0xE8E8F0F0E1LL;
int lastmsg = 1;
String theMessage = "";
char theChar = 0;
int xBuffer[5];
int yBuffer[5];
int bufferVal = 0;
int xDir;
int yDir;
int buttonVal;
int zeroLine = 50;
void setup(void)
{
Serial.begin(115200);
radio.begin();
radio.openReadingPipe(1,pipe);
radio.startListening();
Serial.println("STOP");
analogWrite(l2_motor, 0);
analogWrite(l1_motor, 0);
analogWrite(r1_motor, 0);
analogWrite(r2_motor, 0);
}
void loop(void)
{
while(!radio.available());
radio.read(msg, 1);
theChar = msg[0];
if(msg[0] == '*'){
radio.read(msg, 1);
theChar = msg[0];
while(msg[0] != '&'){
if (theChar != NULL){
theMessage.concat(theChar);
}
radio.read(msg, 1);
theChar = msg[0];
}
if (bufferVal <= 4){
int delimiter = theMessage.indexOf(',');
int delimiter2 = theMessage.indexOf(',', (delimiter+1));
int length = theMessage.length();
char charBuf[length];
theMessage.substring(0,delimiter).toCharArray(charBuf,length);
buttonVal = atof(charBuf);
theMessage.substring(delimiter+1, delimiter2).toCharArray(charBuf,length);
xBuffer[bufferVal] = (int)atof(charBuf);
//Serial.print(xBuffer[bufferVal]); Serial.print('\t');
theMessage.substring(delimiter2+1, theMessage.length()).toCharArray(charBuf,length);
yBuffer[bufferVal] = (int)atof(charBuf);
//Serial.print(yBuffer[bufferVal]);
//Serial.print('\t');
//Filter out noise due to high numbers
if (xBuffer[bufferVal] <= 1023 && xBuffer[bufferVal] >= 0 && yBuffer[bufferVal] <= 1023 && yBuffer[bufferVal] >= 0)
{
bufferVal = bufferVal + 1;
}
//Filter out noise due to random shifts
if(bufferVal >= 2 && xBuffer[bufferVal] == xBuffer[bufferVal-2])
{
if (xBuffer[bufferVal-1] != xBuffer[bufferVal] && xBuffer[bufferVal-1] != xBuffer[bufferVal-2])
{
xBuffer[bufferVal-1] = xBuffer[bufferVal];
}
if (yBuffer[bufferVal-1] != yBuffer[bufferVal] && yBuffer[bufferVal-1] != yBuffer[bufferVal-2])
{
yBuffer[bufferVal-1] = yBuffer[bufferVal];
}
}
}
else {
bufferVal = 0;
xDir = (xBuffer[0] + xBuffer[1] + xBuffer[2] + xBuffer[3] + xBuffer[4])/5;
//Serial.print(xDir); Serial.print('\t');
yDir = (yBuffer[0] + yBuffer[1] + yBuffer[2] + yBuffer[3] + yBuffer[4])/5;
//Serial.println(yDir);
//Serial.print('\t');
if (xDir <= 1023 && yDir <= 1023){
xDir = map(xDir, 0, 1023, -255, 255);
//Serial.print(xDir); Serial.print('\t');
yDir = map(yDir, 0, 1023, -255, 255);
//Serial.println(yDir);
}
}
int diff = abs(xDir) - abs(yDir);
//GO FORWARD
if(xDir > zeroLine){
Serial.println("FORWARD");
analogWrite(l1_motor, xDir);
analogWrite(l2_motor, 0);
analogWrite(r1_motor, xDir);
analogWrite(r2_motor, 0);
}
//GO BACKWARD
else if(xDir < -zeroLine){
Serial.println("BACKWARD");
analogWrite(l2_motor, abs(xDir));
analogWrite(l1_motor, abs(0));
analogWrite(r2_motor, abs(xDir));
analogWrite(r1_motor, abs(0));
}
//TURN RIGHT
if(yDir > zeroLine){
Serial.println("RIGHT");
analogWrite(l1_motor, yDir);
analogWrite(l2_motor, 0);
analogWrite(r1_motor, 0);
analogWrite(r2_motor, yDir);
}
//TURN LEFT
else if(yDir < -zeroLine){
Serial.println("LEFT");
analogWrite(l2_motor, abs(yDir));
analogWrite(l1_motor, abs(0));
analogWrite(r2_motor, 0);
analogWrite(r1_motor, abs(yDir));
}
//STOP
else if (abs(yDir) < abs(zeroLine) && abs(xDir) < abs(zeroLine) ){
Serial.println("STOP");
analogWrite(l2_motor, 0);
analogWrite(l1_motor, 0);
analogWrite(r1_motor, 0);
analogWrite(r2_motor, 0);
}
}
// //Serial.println(theMessage);
// Serial.print(buttonVal); Serial.print('\t');
// Serial.print(xDir); Serial.print('\t');
// Serial.println(yDir);
theMessage = "";
//delay(1);
}
| 24.979275
| 121
| 0.584526
|
1b0e8dbed00d873deb589c1d09a337fb06d6bcd3
| 400
|
ino
|
Arduino
|
FaceRecognition/code/video/trigger_led/trigger_led.ino
|
kaustubh2000/FaceRecognition
|
5fd6cdff27a74a5aff28132579e984fa2dc5afdf
|
[
"Apache-2.0"
] | 1
|
2021-07-10T08:11:17.000Z
|
2021-07-10T08:11:17.000Z
|
FaceRecognition/code/video/trigger_led/trigger_led.ino
|
kaustubh2000/FaceRecognition
|
5fd6cdff27a74a5aff28132579e984fa2dc5afdf
|
[
"Apache-2.0"
] | null | null | null |
FaceRecognition/code/video/trigger_led/trigger_led.ino
|
kaustubh2000/FaceRecognition
|
5fd6cdff27a74a5aff28132579e984fa2dc5afdf
|
[
"Apache-2.0"
] | 2
|
2020-08-03T12:14:06.000Z
|
2020-12-03T16:47:48.000Z
|
int led = 13;
int ret_val;
void setup()
{
Serial.begin(9600);
pinMode (led, OUTPUT);
digitalWrite (led, LOW);
Serial.println("Initialising board");
}
void loop()
{
while (Serial.available()) {
ret_val = Serial.read();
}
if (ret_val == '1') {
// Serial.println("Lighting up LED");
digitalWrite (led, HIGH);
} else if (ret_val == '0') {
digitalWrite (led, LOW);
}
}
| 16
| 39
| 0.595
|
b419bd66dab7d6c1f30883c2cdec88ecb6985c72
| 8,122
|
ino
|
Arduino
|
examples/FT81xmania/GD2U_JAP_Graph4a/GD2U_JAP_Graph4a.ino
|
FT81xMania/GD23ZU
|
79674a4f09db0b460a32a9c6b6c1e9a38ece9fcc
|
[
"BSD-3-Clause"
] | 7
|
2018-06-24T21:53:29.000Z
|
2020-05-09T19:37:40.000Z
|
examples/FT81xmania/GD2U_JAP_Graph4a/GD2U_JAP_Graph4a.ino
|
FT81xMania/GD23ZU
|
79674a4f09db0b460a32a9c6b6c1e9a38ece9fcc
|
[
"BSD-3-Clause"
] | 2
|
2018-08-18T21:54:48.000Z
|
2018-10-01T15:18:08.000Z
|
examples/FT81xmania/GD2U_JAP_Graph4a/GD2U_JAP_Graph4a.ino
|
FT81xMania/GD23ZU
|
79674a4f09db0b460a32a9c6b6c1e9a38ece9fcc
|
[
"BSD-3-Clause"
] | 5
|
2018-09-06T09:51:37.000Z
|
2020-06-27T12:13:20.000Z
|
#include <GD23ZU.h>
const short y_data[] = {
939, 940, 941, 942, 944, 945, 946, 947, 951, 956,
962, 967, 973, 978, 983, 989, 994, 1000, 1005, 1015,
1024, 1034, 1043, 1053, 1062, 1075, 1087, 1100, 1112, 1121,
1126, 1131, 1136, 1141, 1146, 1151, 1156, 1164, 1172, 1179,
1187, 1194, 1202, 1209, 1216, 1222, 1229, 1235, 1241, 1248,
1254, 1260, 1264, 1268, 1271, 1275, 1279, 1283, 1287, 1286,
1284, 1281, 1279, 1276, 1274, 1271, 1268, 1266, 1263, 1261,
1258, 1256, 1253, 1251, 1246, 1242, 1237, 1232, 1227, 1222,
1218, 1215, 1211, 1207, 1203, 1199, 1195, 1191, 1184, 1178,
1171, 1165, 1159, 1152, 1146, 1141, 1136, 1130, 1125, 1120,
1115, 1110, 1103, 1096, 1088, 1080, 1073, 1065, 1057, 1049,
1040, 1030, 1021, 1012, 1004, 995, 987, 982, 978, 974};
Bitmap title, xaxis, yaxis, Gtipo1E, Gtipo1, Gtipo2E, Gtipo2, Gtipo3E, Gtipo3, Gtipo4E, Gtipo4, Gtipo5E, Gtipo5, Gtipo6E, Gtipo6, Gtipo7E, Gtipo7;
char TX[50];
int graph=1;
int A=50, AC=50, AT=50;
int B=2, BC=2, BT=2;
//Marco para graficar
int PX0=50, PY0=50, PXMAX=450-PX0, PYMAX=PY0+230, PYBase= PY0+225;
int esp=2;
void setup()
{
//GD.begin();
GD.begin(GD_STORAGE);
title.fromtext(30, "Graph test");
xaxis.fromtext(28, "X axis");
yaxis.fromtext(28, "Y axis");
Gtipo1E.fromtext(26, " 2"); Gtipo1.fromtext(28, "y = 0.001x");
Gtipo2E.fromtext(26, " 2"); Gtipo2.fromtext(28, "y = 0.5x");
Gtipo3E.fromtext(26, " 2"); Gtipo3.fromtext(28, "y = 0.5x-0.0008x");
Gtipo4E.fromtext(26, " 2"); Gtipo4.fromtext(28, "y = AsinBx");
Gtipo5E.fromtext(26, " 2"); Gtipo5.fromtext(28, "y = AcosBx");
Gtipo6E.fromtext(26, " 2"); Gtipo6.fromtext(28, "y = AtanBx");
Gtipo7E.fromtext(26, " 2"); Gtipo7.fromtext(28, "y = f(array[x])");
}
void loop()
{
GD.ClearColorRGB(0x000010);
GD.Clear(); GD.get_inputs();
GD.ColorRGB(0xffffff);
title.draw(PXMAX/2, PY0-20);
yaxis.draw(PX0-20, PYMAX, DEGREES(270));
xaxis.draw(PXMAX/2, PYMAX+20);
GD.Tag(1); Gtipo1E.draw(130+20, 90-25+PYMAX+20); Gtipo1.draw(100+20, 100-30+PYMAX+20); GD.Tag(255);
GD.Tag(2); Gtipo2.draw(88+20, 100+PYMAX+20); GD.Tag(255);
GD.Tag(3); Gtipo3E.draw(175+20, 100+25+PYMAX+20); Gtipo3.draw(130+20, 100+30+PYMAX+20); GD.Tag(255);
GD.Tag(4); Gtipo4.draw(100+20, 100+60+PYMAX+20); GD.Tag(255);
GD.Tag(5); Gtipo5.draw(320+20, 100+60+PYMAX+20); GD.Tag(255);
GD.Tag(6); Gtipo6.draw(520+20, 100+60+PYMAX+20); GD.Tag(255);
GD.Tag(7); Gtipo7.draw(700+20, 100+60+PYMAX+20); GD.Tag(255);
MarcoG();
if(graph==1){
GD.ColorRGB(0x50ff00); GD.Begin(LINE_STRIP); GD.LineWidth(24); Trace1();
GD.ColorRGB(0xffffff); GD.Begin(POINTS); GD.PointSize(4*16); Trace1Random();}
if(graph==2){
GD.ColorRGB(0x50ff00); GD.Begin(LINE_STRIP); GD.LineWidth(24); Trace2();
GD.ColorRGB(0xffffff); GD.Begin(POINTS); GD.PointSize(4*16); Trace2();}
if(graph==3){
GD.ColorRGB(0x50ff00); GD.Begin(LINE_STRIP); GD.LineWidth(24); Trace3();
GD.ColorRGB(0xffffff); GD.Begin(POINTS); GD.PointSize(4*16); Trace3();}
if(graph==4){
GD.ColorRGB(0x50ff00); GD.Begin(LINE_STRIP); GD.LineWidth(24); SIN();
GD.ColorRGB(0xffffff); GD.Begin(POINTS); GD.PointSize(1*16); SIN();
GD.cmd_fgcolor(0x000050);
GD.Tag(11); GD.cmd_button(500, 250, 120, 60, 29, 0, "B-"); GD.Tag(255);
GD.Tag(12); GD.cmd_button(660, 250, 120, 60, 29, 0, "B+"); GD.Tag(255);
GD.Tag(13); GD.cmd_button(580, 170, 120, 60, 29, 0, "A+"); GD.Tag(255);
GD.Tag(14); GD.cmd_button(580, 330, 120, 60, 29, 0, "A-"); GD.Tag(255);
if (GD.inputs.tag==11)
{
B=B-1;
if(B<=1){B=1;}
}
if (GD.inputs.tag==12)
{
B=B+1;
if(B>=18){B=18;}
}
if (GD.inputs.tag==13)
{
A=A+10;
if(A>=150){A=150;}
}
if (GD.inputs.tag==14)
{
A=A-10;
if(A<=50){A=50;}
}
}
if(graph==5){
GD.get_inputs();
GD.ColorRGB(0x50ff00); GD.Begin(LINE_STRIP); GD.LineWidth(24); COS();
GD.ColorRGB(0xffffff); GD.Begin(POINTS); GD.PointSize(1*16); COS();
GD.cmd_fgcolor(0x005000);
GD.Tag(15); GD.cmd_button(500, 250, 120, 60, 29, 0, "B-"); GD.Tag(255);
GD.Tag(16); GD.cmd_button(660, 250, 120, 60, 29, 0, "B+"); GD.Tag(255);
GD.Tag(17); GD.cmd_button(580, 170, 120, 60, 29, 0, "A+"); GD.Tag(255);
GD.Tag(18); GD.cmd_button(580, 330, 120, 60, 29, 0, "A-"); GD.Tag(255);
if (GD.inputs.tag==15)
{
BC=BC-1;
if(BC<=1){BC=1;}
}
if (GD.inputs.tag==16)
{
BC=BC+1;
if(BC>=18){BC=18;}
}
if (GD.inputs.tag==17)
{
AC=AC+10;
if(AC>=150){AC=150;}
}
if (GD.inputs.tag==18)
{
AC=AC-10;
if(AC<=50){AC=50;}
}
}
if(graph==6){
//GD.ColorRGB(0x50ff00); GD.Begin(LINE_STRIP); GD.LineWidth(24); TAN();
GD.ColorRGB(0x50ffff); GD.Begin(POINTS); GD.PointSize(1*16); TAN();
GD.cmd_fgcolor(0x500000);
GD.Tag(19); GD.cmd_button(500, 250, 120, 60, 29, 0, "B-"); GD.Tag(255);
GD.Tag(20); GD.cmd_button(660, 250, 120, 60, 29, 0, "B+"); GD.Tag(255);
GD.Tag(21); GD.cmd_button(580, 170, 120, 60, 29, 0, "A+"); GD.Tag(255);
GD.Tag(22); GD.cmd_button(580, 330, 120, 60, 29, 0, "A-"); GD.Tag(255);
if (GD.inputs.tag==19)
{
BT=BT-1;
if(BT<=1){BT=1;}
}
if (GD.inputs.tag==20)
{
BT=BT+1;
if(BT>=18){BT=18;}
}
if (GD.inputs.tag==21)
{
AT=AT+10;
if(AT>=150){AT=150;}
}
if (GD.inputs.tag==22)
{
AT=AT-10;
if(AT<=50){AT=50;}
}
}
if(graph==7){
//GD.ColorRGB(0x50ff00); GD.Begin(LINE_STRIP); GD.LineWidth(24); GArray();
GD.ColorRGB(0x00ff00); GD.Begin(POINTS); GD.PointSize(1*16); GArray();
sprintf(TX,"esp = %d", esp);
GD.Tag(23); GD.ColorRGB(0xffffff); GD.cmd_button(500, 250, 120, 60, 29, 0, TX); GD.Tag(255);
if (GD.inputs.tag==23)
{
delay(95);
esp=esp+1;
if(esp>=3){esp=0;}
}
}
if (GD.inputs.tag==1)
{
graph=1;
}
if (GD.inputs.tag==2)
{
graph=2;
}
if (GD.inputs.tag==3)
{
graph=3;
}
if (GD.inputs.tag==4)
{
graph=4;
}
if (GD.inputs.tag==5)
{
graph=5;
}
if (GD.inputs.tag==6)
{
graph=6;
}
if (GD.inputs.tag==7)
{
graph=7;
}
GD.swap();
}
void Trace1()
{
for (float x = 0; x < (PXMAX-10); x += 20) {
float y = PYBase - ((0.001*x*(x)));
GD.Vertex2f((x+PX0)*16, y*16);
}
}
void Trace1Random()
{
for (float x = 0; x < (PXMAX-10); x += 20) {
float y = PYBase - ((0.001*x*(x+random(-30,30))));
GD.Vertex2f((x+PX0)*16, y*16);
}
}
void Trace2()
{
for (float x = 0; x < (PXMAX-10); x += 20) {
float y = PYBase - ((0.5*x));
GD.Vertex2f((x+PX0)*16, y*16);
}
}
void Trace3()
{
for (float x = 0; x < (PXMAX-10); x += 20) {
float y = PYBase - ((0.5*x)-0.0008*x*x);
GD.Vertex2f((x+PX0)*16, y*16);
}
}
void SIN(){
for ( long i = 0 ; i<=359 ; i++)
{
GD.Vertex2f((i+PX0)*16, (PYBase-(A*sin((B*i*PI)/180)))*16);
}
}
void COS(){
for ( long j = 0 ; j<=359 ; j++)
{
GD.Vertex2f((j+PX0)*16, (PYBase-(AC*cos((BC*j*PI)/180)))*16);
}
}
void TAN(){
for ( long j = 0 ; j<=359 ; j++)
{
GD.Vertex2f((j+PX0)*16, (PYBase-(AT*tan((BT*j*PI)/180)))*16);
}
}
void MarcoG()
{
GD.Begin(LINES);
GD.Vertex2f(PX0*16, PY0*16); GD.Vertex2f(PX0*16, (PYMAX+170)*16);
GD.Vertex2f(PX0*16, (PYMAX-4)*16); GD.Vertex2f((PXMAX+PX0)*16, (PYMAX-4)*16);
}
void GArray(){
for ( long j = 0 ; j<=119 ; j++)
{
GD.Vertex2f((j+PX0+esp*j)*16, (PYBase-(y_data[j]/10))*16);
}
}
| 26.456026
| 146
| 0.516006
|
fcfed138e7d3d1c5608ca1832d19d42a03912a45
| 10,593
|
ino
|
Arduino
|
thewholething.ino
|
zrider99zr/steamcontrollermelee
|
b4867624774215372705a901c344ed1070cd6baf
|
[
"MIT"
] | null | null | null |
thewholething.ino
|
zrider99zr/steamcontrollermelee
|
b4867624774215372705a901c344ed1070cd6baf
|
[
"MIT"
] | null | null | null |
thewholething.ino
|
zrider99zr/steamcontrollermelee
|
b4867624774215372705a901c344ed1070cd6baf
|
[
"MIT"
] | null | null | null |
// I/O
#define LED 13
#define PIN 23
// Right side buttons
#define S_START 0
#define S_L 1
#define S_Y 2
#define S_R 3
#define S_TILT 4
#define S_B 5
#define S_A 6
#define S_X 7
#define S_Z 8
#define S_CUP 9
#define S_CLEFT 10
#define S_CDOWN 11
#define S_CRIGHT 12
// Left side buttons
#define S_TAUNT 22
#define S_AUP 21
#define S_ALEFT 20
#define S_ADOWN 19
#define S_ARIGHT 18
#define S_TUP 17
#define S_TLEFT 16
#define S_TDOWN 15
#define S_TRIGHT 14
// Bitmasks
#define bit0(x) x & (1 << 0)
#define bit1(x) x & (1 << 1)
#define bit2(x) x & (1 << 2)
#define bit3(x) x & (1 << 3)
#define bit4(x) x & (1 << 4)
#define bit5(x) x & (1 << 5)
#define bit6(x) x & (1 << 6)
#define bit7(x) x & (1 << 7)
// more bitmasks
#define setBit0(x) x | (1 << 0)
#define setBit1(x) x | (1 << 1)
#define setBit2(x) x | (1 << 2)
#define setBit3(x) x | (1 << 3)
#define setBit4(x) x | (1 << 4)
#define setBit5(x) x | (1 << 5)
#define setBit6(x) x | (1 << 6)
#define setBit7(x) x | (1 << 7)
// Minimum analog stick axis value
#define A_MIN 48
// Middle analog stick axis value
#define A_MID 128
// Maximum analog stick axis value
#define A_MAX 208
// The lightest shield value
#define A_TRIGGER 43
// Smallest tilt offset possible
#define O_MIN 25
// Middle analog offset
// Jump/Shield drop on y-axis
// Walk/tilt on x-axis
#define O_MID 53 // 53, 54, or 55
// Max analog offset
// basically only used for angles
#define O_MAX 70
// Period length is 5 us
// 72 MHz * 2.5 us
#define CYCLES_HALF 180
// Period length is 5 us
// 72 MHz * 10 us
#define CYCLES_TWO 720
bool passedAll = false;
uint32_t fallTime = 0;
uint32_t buffer = 0;
uint8_t bitsRead = 0;
void setup() {
cli();
pinMode(PIN, INPUT);
pinMode(LED, OUTPUT);
digitalWrite(LED, LOW);
pinMode(S_START, INPUT_PULLUP);
pinMode(S_L, INPUT_PULLUP);
pinMode(S_Y, INPUT_PULLUP);
pinMode(S_R, INPUT_PULLUP);
pinMode(S_TILT, INPUT_PULLUP);
pinMode(S_B, INPUT_PULLUP);
pinMode(S_A, INPUT_PULLUP);
pinMode(S_X, INPUT_PULLUP);
pinMode(S_Z, INPUT_PULLUP);
pinMode(S_CUP, INPUT_PULLUP);
pinMode(S_CLEFT, INPUT_PULLUP);
pinMode(S_CDOWN, INPUT_PULLUP);
pinMode(S_CRIGHT, INPUT_PULLUP);
pinMode(S_TAUNT, INPUT_PULLUP);
pinMode(S_AUP, INPUT_PULLUP);
pinMode(S_ALEFT, INPUT_PULLUP);
pinMode(S_ADOWN, INPUT_PULLUP);
pinMode(S_ARIGHT, INPUT_PULLUP);
pinMode(S_TUP, INPUT_PULLUP);
pinMode(S_TLEFT, INPUT_PULLUP);
pinMode(S_TDOWN, INPUT_PULLUP);
pinMode(S_TRIGHT, INPUT_PULLUP);
ARM_DEMCR |= ARM_DEMCR_TRCENA;
ARM_DWT_CTRL |= ARM_DWT_CTRL_CYCCNTENA;
}
void loop() {
while (1) {
// Wait for falling edge
while (digitalReadFast(PIN) == HIGH);
uint32_t newFallTime = ARM_DWT_CYCCNT;
if (newFallTime - fallTime > CYCLES_TWO) {
// start of new command
buffer = 0;
bitsRead = 0;
}
fallTime = newFallTime;
// Wait for rising edge
while (digitalReadFast(PIN) == LOW);
uint32_t cycles = ARM_DWT_CYCCNT - fallTime;
buffer = (buffer << 1) | (cycles > CYCLES_HALF ? 0 : 1);
bitsRead++;
if (bitsRead == 9) {
if (buffer & 0x1) {
handleShort(buffer >> 1);
}
} else if (bitsRead == 25) {
if (buffer & 0x1) {
handleLong(buffer >> 1);
}
}
}
}
void handleShort(uint32_t buffer) {
if (buffer == 0x0) {
respondWithId();
} else if (buffer == 0x41) {
respondWithOrigins();
}
}
void handleLong(uint32_t buffer) {
// the bottom two bits of the command control rumble.
// mask them out cuz we don't care, but for reference:
// XXXXXX00, brake off, motor off
// XXXXXX01, brake off, motor on
// XXXXXX10, brake on, motor off
// XXXXXX11, brake on, motor on? idk
buffer &= 0xFFFFFFFC;
if (buffer == 0x00400000) {
respondWithCalibration();
} else {
// Technically, we should check for the right commands
// before responding, but we don't actually know what
// all the commands are
if (!passedAll) {
digitalWriteFast(LED, HIGH);
passedAll = true;
}
respondWithData();
}
}
void respondWithId() {
pinMode(PIN, OUTPUT);
digitalWriteFast(PIN, HIGH);
// 0x09 0x00 0x00 STOP
send0(); send0(); send0(); send0(); send1(); send0(); send0(); send1();
send0(); send0(); send0(); send0(); send0(); send0(); send0(); send0();
send0(); send0(); send0(); send0(); send0(); send0(); send0(); send0();
send1();
pinMode(PIN, INPUT);
}
void respondWithOrigins() {
pinMode(PIN, OUTPUT);
digitalWriteFast(PIN, HIGH);
// 0x00 0x80 0x80 0x80 0x80 0x80 0x00 0x00 0x02 0x02 STOP
send0(); send0(); send0(); send0(); send0(); send0(); send0(); send0();
send1(); send0(); send0(); send0(); send0(); send0(); send0(); send0();
send1(); send0(); send0(); send0(); send0(); send0(); send0(); send0();
send1(); send0(); send0(); send0(); send0(); send0(); send0(); send0();
send1(); send0(); send0(); send0(); send0(); send0(); send0(); send0();
send1(); send0(); send0(); send0(); send0(); send0(); send0(); send0();
send0(); send0(); send0(); send0(); send0(); send0(); send0(); send0();
send0(); send0(); send0(); send0(); send0(); send0(); send0(); send0();
send0(); send0(); send0(); send0(); send0(); send0(); send1(); send0();
send0(); send0(); send0(); send0(); send0(); send0(); send1(); send0();
send1();
pinMode(PIN, INPUT);
}
void respondWithCalibration() {
pinMode(PIN, OUTPUT);
digitalWriteFast(PIN, HIGH);
// 0x00 0x80 0x80 0x80 0x80 0x80 0x00 0x00 STOP
send0(); send0(); send0(); send0(); send0(); send0(); send0(); send0();
send1(); send0(); send0(); send0(); send0(); send0(); send0(); send0();
send1(); send0(); send0(); send0(); send0(); send0(); send0(); send0();
send1(); send0(); send0(); send0(); send0(); send0(); send0(); send0();
send1(); send0(); send0(); send0(); send0(); send0(); send0(); send0();
send1(); send0(); send0(); send0(); send0(); send0(); send0(); send0();
send0(); send0(); send0(); send0(); send0(); send0(); send0(); send0();
send0(); send0(); send0(); send0(); send0(); send0(); send0(); send0();
send1();
pinMode(PIN, INPUT);
}
void respondWithData() {
bool pStart = digitalReadFast(S_START) == LOW;
bool pL = digitalReadFast(S_L) == LOW;
bool pY = digitalReadFast(S_Y) == LOW;
bool pR = digitalReadFast(S_R) == LOW;
bool pTilt = digitalReadFast(S_TILT) == LOW;
bool pB = digitalReadFast(S_B) == LOW;
bool pA = digitalReadFast(S_A) == LOW;
bool pX = digitalReadFast(S_X) == LOW;
bool pZ = digitalReadFast(S_Z) == LOW;
bool pCUp = digitalReadFast(S_CUP) == LOW;
bool pCLeft = digitalReadFast(S_CLEFT) == LOW;
bool pCDown = digitalReadFast(S_CDOWN) == LOW;
bool pCRight = digitalReadFast(S_CRIGHT) == LOW;
bool pTaunt = digitalReadFast(S_TAUNT) == LOW;
bool pAUp = digitalReadFast(S_AUP) == LOW;
bool pALeft = digitalReadFast(S_ALEFT) == LOW;
bool pADown = digitalReadFast(S_ADOWN) == LOW;
bool pARight = digitalReadFast(S_ARIGHT) == LOW;
bool pTUp = digitalReadFast(S_TUP) == LOW;
bool pTLeft = digitalReadFast(S_TLEFT) == LOW;
bool pTDown = digitalReadFast(S_TDOWN) == LOW;
bool pTRight = digitalReadFast(S_TRIGHT) == LOW;
uint8_t data[8];
// 0x07: [0]
// 0x06: [0]
// 0x05: [0]
// 0x04: Start
// 0x03: Y
// 0x02: X
// 0x01: B
// 0x00: A
data[0] = 0x00;
if (pStart) data[0] = setBit4(data[0]);
if (pY) data[0] = setBit3(data[0]);
if (pX) data[0] = setBit2(data[0]);
if (pB) data[0] = setBit1(data[0]);
if (pA) data[0] = setBit0(data[0]);
// 0x07: [1]
// 0x06: L
// 0x05: R
// 0x04: Z
// 0x03: DPad Up
// 0x02: DPad Down
// 0x01: DPad Right
// 0x00: Dpad Left
data[1] = 0x80;
if (pL && !pTilt) data[1] = setBit6(data[1]);
if (pR && !pTilt) data[1] = setBit5(data[1]);
if (pZ) data[1] = setBit4(data[1]);
if (pTaunt) data[1] = setBit3(data[1]);
// Analog X
if (pALeft && pARight) {
// TODO: conflict resolution
data[2] = A_MID;
} else if (pALeft) {
if (pTLeft && pTDown) {
data[2] = A_MID - O_MAX;
} else if (pTLeft) {
data[2] = A_MID - O_MIN;
} else if (pTDown) {
data[2] = A_MID - O_MID;
} else {
data[2] = A_MIN;
}
} else if (pARight) {
if (pTLeft && pTDown) {
data[2] = A_MID + O_MAX;
} else if (pTLeft) {
data[2] = A_MID + O_MIN;
} else if (pTDown) {
data[2] = A_MID + O_MID;
} else {
data[2] = A_MAX;
}
} else {
data[2] = A_MID;
}
// Analog Y
if (pADown && pAUp) {
// TODO: conflict resolution
data[3] = A_MID;
} else if (pADown) {
if (pTUp && pTRight) {
data[3] = A_MID - O_MAX;
} else if (pTUp) {
data[3] = A_MID - O_MIN;
} else if (pTRight) {
data[3] = A_MID - O_MID;
} else {
data[3] = A_MIN;
}
} else if (pAUp) {
if (pTUp && pTRight) {
data[3] = A_MID + O_MAX;
} else if (pTUp) {
data[3] = A_MID + O_MIN;
} else if (pTRight) {
data[3] = A_MID + O_MID;
} else {
data[3] = A_MAX;
}
} else {
data[3] = A_MID;
}
// CStick X
if (pCLeft && pCRight) {
// TODO: conflict resolution
data[4] = A_MID;
} else if (pCLeft) {
data[4] = A_MIN;
} else if (pCRight) {
data[4] = A_MAX;
} else {
data[4] = A_MID;
}
// CStick Y
if (pCDown && pCUp) {
// TODO: conflict resolution
data[5] = A_MID;
} else if (pCDown) {
data[5] = A_MIN;
} else if (pCUp) {
data[5] = A_MAX;
} else {
data[5] = A_MID;
}
// Left Trigger
if (pL && pTilt) {
data[6] = A_TRIGGER;
} else {
data[6] = 0x00;
}
// Right Trigger
if (pR && pTilt) {
data[7] = A_TRIGGER;
} else {
data[7] = 0x00;
}
pinMode(PIN, OUTPUT);
digitalWriteFast(PIN, HIGH);
for(int i = 0; i < 8; i++) {
if (bit7(data[i])) send1(); else send0();
if (bit6(data[i])) send1(); else send0();
if (bit5(data[i])) send1(); else send0();
if (bit4(data[i])) send1(); else send0();
if (bit3(data[i])) send1(); else send0();
if (bit2(data[i])) send1(); else send0();
if (bit1(data[i])) send1(); else send0();
if (bit0(data[i])) send1(); else send0();
}
send1();
pinMode(PIN, INPUT);
}
// pinMode must be set to OUTPUT
void send0() {
digitalWriteFast(PIN, LOW);
delayMicroseconds(3);
digitalWriteFast(PIN, HIGH);
delayMicroseconds(1);
}
// pinMode must be set to OUTPUT
void send1() {
digitalWriteFast(PIN, LOW);
delayMicroseconds(1);
digitalWriteFast(PIN, HIGH);
delayMicroseconds(3);
}
| 25.463942
| 73
| 0.592372
|
494fc00d4a76b4292005a48ef3e0cfecaf014c92
| 2,804
|
ino
|
Arduino
|
NodeMcu_Blynk_v2_led_test2/NodeMcu_Blynk_v2_led_test2.ino
|
luckyhegde/NodeMCU_Tests
|
a3c71cb83896950cbab520decdba10b2ec2849ec
|
[
"MIT"
] | null | null | null |
NodeMcu_Blynk_v2_led_test2/NodeMcu_Blynk_v2_led_test2.ino
|
luckyhegde/NodeMCU_Tests
|
a3c71cb83896950cbab520decdba10b2ec2849ec
|
[
"MIT"
] | null | null | null |
NodeMcu_Blynk_v2_led_test2/NodeMcu_Blynk_v2_led_test2.ino
|
luckyhegde/NodeMCU_Tests
|
a3c71cb83896950cbab520decdba10b2ec2849ec
|
[
"MIT"
] | null | null | null |
#define BLYNK_DEBUG // Optional, this enables lots of prints
#define BLYNK_PRINT Serial // Comment this out to disable prints and save space
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SimpleTimer.h>
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "55e4f2a287204fa69198463002d400c8";
int ledPin2=2; // assign widget LED to tie with gpio pin 2
WidgetLED led(V2);
int led2value = digitalRead(ledPin2);
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "lucky_home";
char pass[] = "laxmish53";
SimpleTimer timer;
void setup()
{
Serial.begin(9600);
Blynk.begin(auth, ssid, pass);
timer.setInterval(1000L, blinkLedWidget);
}
// V2 LED Widget is blinking
void blinkLedWidget()
{
if (led2value == 0) {
led.off();
// Blynk.virtualWrite(V2, LOW);
Serial.println("LED on V2: off");
} else {
led.on();
// Blynk.virtualWrite(V2, HIGH);
Serial.println("LED on V2: on");
}
}
void loop()
{
Blynk.run();
timer.run();
Serial.print("LED on V2: ");
Serial.println(led2value);
Blynk.syncVirtual(V2);
BLYNK_LOG("This is my value: %d", 10);
delay(1000);
} /*
BLYNK_CONNECTED()
{
if (isFirstConnect) {
Blynk.syncVirtual(V2);
//Blynk.syncAll();
}
BLYNK_READ(V5) // Widget in the app READs Virtal Pin V5 with the certain frequency
{
// This command writes Arduino's uptime in seconds to Virtual Pin V5
Blynk.virtualWrite(5, millis() / 1000);
}
}BLYNK_WRITE(V1) // Widget WRITEs to Virtual Pin V1
{
int x = param[0].asInt(); // getting first value
int y = param[1].asInt(); // getting second value
int z = param[N].asInt(); // getting N value
}*/
/* if (led2value == 1 ){
Blynk.virtualWrite(V2, HIGH);}
else
{
Blynk.virtualWrite(V2, LOW);}
BLYNK_WRITE(V2); //Button Widget is writing to pin V2
{
int pinData = led2value;
}*/
/*
// V2 LED Widget is fading
void fadeLedWidget()
{
static int value = 0;
static int delta = 30;
value += delta;
if (value > 255 || value < 0) {
delta = -delta;
} else {
Serial.print("LED on V2: ");
Serial.println(value);
led2.setValue(value);
}
}*/
/*
* while (Blynk.connect() == false) {
// Wait until connected
}
// Make pin 2 default HIGH, and attach INT to our handler
pinMode(2, INPUT_PULLUP);
}
int prevState = -1;
int currState = -1;
long lastChangeTime = 0;
* void checkPin()
{
// Invert state, since button is "Active LOW"
int state = !digitalRead(2);
// Debounce mechanism
long t = millis();
if (state != prevState) {
lastChangeTime = t;
}
if (t - lastChangeTime > 50) {
if (state != currState) {
currState = state;
Blynk.virtualWrite(V2, state);
}
}
prevState = state;
}
*/
| 22.253968
| 84
| 0.64087
|
3c79f8dfe02c631f95c17c6e869bb6e50bd18e53
| 825
|
ino
|
Arduino
|
sketch_fan/sketch_fan.ino
|
udarakr/sketches
|
0429bceaa305db57b66b126398d2a7871c94c177
|
[
"Apache-2.0"
] | null | null | null |
sketch_fan/sketch_fan.ino
|
udarakr/sketches
|
0429bceaa305db57b66b126398d2a7871c94c177
|
[
"Apache-2.0"
] | null | null | null |
sketch_fan/sketch_fan.ino
|
udarakr/sketches
|
0429bceaa305db57b66b126398d2a7871c94c177
|
[
"Apache-2.0"
] | null | null | null |
const int sensorPin = A0;
const int highTemp = 2;
const int lowTemp = 3;
const int optocouplerPin = 8;
void setup()
{
pinMode(optocouplerPin, OUTPUT);
pinMode(highTemp, OUTPUT);
pinMode(lowTemp, OUTPUT);
Serial.begin(9600);
}
void loop()
{
//Read the sensor value
int sensorVal = analogRead(sensorPin);
//Convert reading to voltage
float voltage = (sensorVal/1024.0) * 5.0;
//convert millivolts into temperature
float temperature = (voltage - .5) * 100;
Serial.println(temperature);
if(temperature > 33){
digitalWrite(lowTemp, LOW);
digitalWrite(highTemp, HIGH);
digitalWrite(optocouplerPin, HIGH);
}else{
digitalWrite(lowTemp, HIGH);
digitalWrite(highTemp, LOW);
digitalWrite(optocouplerPin, LOW);
}
delay(1000);
}
| 21.153846
| 43
| 0.650909
|
55b264e2613203c592ead142b59cd3c6a15bb1fe
| 2,803
|
ino
|
Arduino
|
examples/demoLCD/demoLCD.ino
|
djuseeq/LcdCustomScroll
|
e95cc0638b9afed84a035c584f3edba8755bbbe2
|
[
"MIT"
] | null | null | null |
examples/demoLCD/demoLCD.ino
|
djuseeq/LcdCustomScroll
|
e95cc0638b9afed84a035c584f3edba8755bbbe2
|
[
"MIT"
] | null | null | null |
examples/demoLCD/demoLCD.ino
|
djuseeq/LcdCustomScroll
|
e95cc0638b9afed84a035c584f3edba8755bbbe2
|
[
"MIT"
] | null | null | null |
/*----------------------------------------------------------------------------
* Author: György Kovács |
* Created: 05 Jul 2020 |
* Description: Create scrolling text elements on character LCD display |
* with delay when reach the end of the string |
*----------------------------------------------------------------------------
*/
#include <Arduino.h>
#include <LiquidCrystal.h> // LCD
#include <LcdCustomScroll.h>
//First, instantiate the LCD object (change values as needed)
//rs, en, d4, d5, d6, d7
LiquidCrystal lcd(4, 5, 6, 7, 8, 9);
//Second, instantiate the scrolling text object(s)
LcdCustomScroll scroll1(lcd);
LcdCustomScroll scroll2(lcd);
LcdCustomScroll scroll3(lcd);
LcdCustomScroll scroll4(lcd);
char longText1[] = "Let's see how this scrolling text works !";
char longText2[] = "The quick brown fox jumps over the lazy dog";
char longText3[] = "This is the third row and this scrolling text is awesome ! ";
char longText4[] = "We do nothing in the fourth line :)";
unsigned long txtTimer1 = 0xFFFF00;
unsigned long txtTimer2 = 0xFFFF00;
unsigned long txtTimer3 = 0xFFFF00;
unsigned long txtTimer4 = 0xFFFF00;
unsigned long timerCnt = 0;
byte counter = 0;
void setup() {
lcd.begin(20, 4);//columns, rows
//First row
scroll1.init(longText1, 300, 0, 9, 16);//Scroll speed(ms), row, from column, to column
scroll1.scrollMode(SCMODE1);//Scroll modes: SCMODE1, SCMODE2, SCMODE3, SCMODE4
//Second row
scroll2.init(longText2, 500, 1, 3, 15);
scroll2.scrollMode(SCMODE2);
//Third row
scroll3.init(longText3, 500, 2, 0, 20);
scroll3.scrollMode(SCMODE3);
//Fourth row
scroll4.init(longText4, 200, 3, 10, 19);
scroll4.scrollMode(SCMODE4);
}//end setup
void loop() {
//Print counter to LCD
if(millis() - timerCnt >= 1000){
char shortText[10];
timerCnt = millis();
if(!counter){
snprintf_P(shortText, sizeof(shortText), PSTR(" "));
lcd.setCursor(0,0);
lcd.print(shortText);
}
snprintf_P(shortText, sizeof(shortText), PSTR("Cnt :%i"),counter);
lcd.setCursor(0,0);
lcd.print(shortText);
counter++;
}//end if print counter
if(millis() - txtTimer1 >= 1000 && scroll1.scrollText()){
txtTimer1 = millis();
}
if(millis() - txtTimer2 >= 1000 && scroll2.scrollText()){
txtTimer2 = millis();
}
if(millis() - txtTimer3 >= 3000 && scroll3.scrollText()){
txtTimer3 = millis();
}
if(millis() - txtTimer4 >= 2000 && scroll4.scrollText()){
txtTimer4 = millis();
}
}//end main loop
| 30.802198
| 91
| 0.564395
|
0a2c0de7c09d4dd5ad2bd73e427da8523b60f6fc
| 3,370
|
ino
|
Arduino
|
Part1-sketches/Extras/Example_07_LumHumTem_Mayfly/Example_07_LumHumTem_Mayfly.ino
|
EnviroDIY/LearnEnviroDIYcode
|
a7b0e5e31ab6762b0051a193481380824f467884
|
[
"BSD-3-Clause"
] | null | null | null |
Part1-sketches/Extras/Example_07_LumHumTem_Mayfly/Example_07_LumHumTem_Mayfly.ino
|
EnviroDIY/LearnEnviroDIYcode
|
a7b0e5e31ab6762b0051a193481380824f467884
|
[
"BSD-3-Clause"
] | 1
|
2018-03-05T19:25:29.000Z
|
2018-03-05T19:25:29.000Z
|
Part1-sketches/Extras/Example_07_LumHumTem_Mayfly/Example_07_LumHumTem_Mayfly.ino
|
EnviroDIY/LearnEnviroDIYcode
|
a7b0e5e31ab6762b0051a193481380824f467884
|
[
"BSD-3-Clause"
] | 2
|
2020-02-01T00:58:24.000Z
|
2021-01-21T22:46:04.000Z
|
//Connect the Grove Digital Humidity and Temperature (DHT) board to D10-11 Grove connector on the Mayfly
#include <Arduino.h>
#include <Wire.h>
#include "DHT.h" // Includes the Adafruit DHT-sensor-library 1.3.0+, which was updated to require the Unified Adafruit_Sensor sensor
#include <Adafruit_TSL2561_U.h> // Adafruit_TSL2561 library for the TSL2561 digital luminosity (light) sensors
// Create an instance of the TLS Sensor, using the correct I2C address
Adafruit_TSL2561_Unified tsl(TSL2561_ADDR_LOW); // I2C address 0x29 (addr pin set LOW)
#define DHTPIN 10 // what pin the DHT signal is connected to
// Uncomment whatever type you're using!
#define DHTTYPE DHT11 // DHT 11
//#define DHTTYPE DHT22 // DHT 22 (AM2302)
//#define DHTTYPE DHT21 // DHT 21 (AM2301)
// Connect pin 1 (on the left) of the sensor to +5V
// Connect pin 2 of the sensor to whatever your DHTPIN is
// Connect pin 4 (on the right) of the sensor to GROUND
// Connect a 10K resistor from pin 2 (data) to pin 1 (power) of the sensor
// Create variables for the full spectrum (broadband) and IR luminosity results
uint16_t broadband, ir;
DHT dht(DHTPIN, DHTTYPE);
void setup()
{
Serial.begin(57600);
if (tsl.begin())
{
Serial.println("Luminosity sensor");
}
else
{
Serial.println("No sensor?");
while (1);
}
// You can change the gain on the fly, to adapt to brighter/dimmer light situations
//tsl.setGain(TSL2561_GAIN_1X); // set no gain (for bright situtations)
tsl.setGain(TSL2561_GAIN_16X); // set 16x gain (for dim situations)
// Changing the integration time gives you a longer time over which to sense light
// longer timelines are slower, but are good in very low light situtations!
tsl.setIntegrationTime(TSL2561_INTEGRATIONTIME_13MS); // shortest integration time (bright light)
//tsl.setIntegrationTime(TSL2561_INTEGRATIONTIME_101MS); // medium integration time (medium light)
//tsl.setIntegrationTime(TSL2561_INTEGRATIONTIME_402MS); // longest integration time (dim light)
pinMode(22, OUTPUT); // Setting up Pin 22 to provide power to Grove Ports
digitalWrite(22, HIGH); // Provide power to D10-11 and D6-7 Grove Ports
delay(200);
Serial.begin(57600);
Serial.println("Digital Humidity/Temperature");
dht.begin();
}
void loop()
{
// Reading temperature or humidity takes about 250 milliseconds
// Sensor readings may also be up to 2 seconds old
float h = dht.readHumidity();
float t = dht.readTemperature();
// Get both the broadband/full spectrum and IR light intensity from the sensor
// These values are returned as raw ADC outputs (non-standard units)
tsl.getLuminosity(&broadband, &ir);
// Print results to the serial port
Serial.print("IR: "); Serial.print(ir); Serial.print("\t\t");
Serial.print("Full: "); Serial.print(broadband); Serial.print(" \t");
Serial.print("Visible: "); Serial.print(broadband - ir); Serial.print("\t");
// Calculate and print illuminance in lux (ie, convert sensor units to the standard SI unit)
Serial.print("Lux: "); Serial.println(tsl.calculateLux(broadband, ir));
Serial.print("Humidity: ");
Serial.print(h);
Serial.print(" %\t");
Serial.print("Temperature: ");
Serial.print(t);
Serial.println(" *C");
delay(1000);
}
| 35.104167
| 137
| 0.698813
|
98c1178b3e9afaca7441bb4e88f93770ff6a3552
| 1,292
|
ino
|
Arduino
|
Teensy - Video Features Only - Remote Control/PTS_Driver_Teensy3-2_TStep/ir Code/IRLib2/examples/send/send.ino
|
cbradburne/Pan-Tilt-Mount
|
a67081495847dd68cc1d47587fd8187d07320ed5
|
[
"MIT"
] | 7
|
2021-01-05T15:19:37.000Z
|
2022-02-02T21:29:31.000Z
|
Teensy - Video Features Only - Remote Control/PTS_Driver_Teensy3-2_TStep/ir Code/IRLib2/examples/send/send.ino
|
cbradburne/Pan-Tilt-Mount
|
a67081495847dd68cc1d47587fd8187d07320ed5
|
[
"MIT"
] | null | null | null |
Teensy - Video Features Only - Remote Control/PTS_Driver_Teensy3-2_TStep/ir Code/IRLib2/examples/send/send.ino
|
cbradburne/Pan-Tilt-Mount
|
a67081495847dd68cc1d47587fd8187d07320ed5
|
[
"MIT"
] | 4
|
2021-07-26T12:06:19.000Z
|
2022-02-17T17:43:23.000Z
|
/* send.ino Example sketch for IRLib2
* Illustrates how to send a code.
*/
#include <IRLibSendBase.h> // First include the send base
//Now include only the protocols you wish to actually use.
//The lowest numbered protocol should be first but remainder
//can be any order.
#include <IRLib_P01_NEC.h>
//#include <IRLib_P02_Sony.h>
#include <IRLibCombo.h> // After all protocols, include this
// All of the above automatically creates a universal sending
// class called "IRsend" containing only the protocols you want.
// Now declare an instance of that sender.
IRsend mySender;
void setup() {
Serial.begin(9600);
delay(2000); while (!Serial); //delay for Leonardo
Serial.println(F("Every time you press a key is a serial monitor we will send."));
}
void loop() {
if (Serial.read() != -1) {
//send a code every time a character is received from the
// serial port. You could modify this sketch to send when you
// push a button connected to an digital input pin.
//Substitute values and protocols in the following statement
// for device you have available.
//mySender.send(SONY,0xa8bca, 20);//Sony DVD power A8BCA, 20 bits
mySender.send(NEC,0x20df10ef,32);//NEC TV power button=0x61a0f00f
Serial.println(F("Sent signal."));
}
}
| 36.914286
| 84
| 0.708978
|
0fe45a34d9bf2fb79f8657a3fd0578b9df9880c6
| 567
|
ino
|
Arduino
|
examples/AUnitPlatformIO/AUnitPlatformIO.ino
|
Nathan-ma/AUnit
|
54925eabd3a78a22049b0e5f1d08443359a90105
|
[
"MIT"
] | 113
|
2018-04-25T12:42:28.000Z
|
2022-03-26T23:20:17.000Z
|
examples/AUnitPlatformIO/AUnitPlatformIO.ino
|
Nathan-ma/AUnit
|
54925eabd3a78a22049b0e5f1d08443359a90105
|
[
"MIT"
] | 47
|
2018-03-29T21:02:19.000Z
|
2022-01-10T15:22:40.000Z
|
examples/AUnitPlatformIO/AUnitPlatformIO.ino
|
Nathan-ma/AUnit
|
54925eabd3a78a22049b0e5f1d08443359a90105
|
[
"MIT"
] | 11
|
2018-07-16T16:42:42.000Z
|
2022-02-20T15:47:35.000Z
|
#line 2 "AUnitPlatformIO.ino"
#include <AUnit.h>
test(exampleTest) {
assertEqual(3, 3);
}
//----------------------------------------------------------------------------
// setup() and loop()
//----------------------------------------------------------------------------
void setup() {
#if ARDUINO
delay(1000); // wait for stability on some boards to prevent garbage Serial
#endif
Serial.begin(115200); // ESP8266 default of 74880 not supported on Linux
while(!Serial); // for the Arduino Leonardo/Micro only
}
void loop() {
aunit::TestRunner::run();
}
| 23.625
| 78
| 0.497354
|
390388a8810a0cfa8e5a22ae350e77d85d0d1906
| 1,624
|
ino
|
Arduino
|
desktop/libraries/Klangstrom/examples/klang/extensions/ExampleTextToSpeechSAM/ExampleTextToSpeechSAM.ino
|
dennisppaul/klangstrom-arduino
|
d1f805b9813d1ec08b5b850abf1270fb037245d9
|
[
"CC0-1.0"
] | 5
|
2021-05-04T07:32:05.000Z
|
2022-01-18T11:04:14.000Z
|
desktop/libraries/Klangstrom/examples/klang/extensions/ExampleTextToSpeechSAM/ExampleTextToSpeechSAM.ino
|
dennisppaul/klangstrom-arduino
|
d1f805b9813d1ec08b5b850abf1270fb037245d9
|
[
"CC0-1.0"
] | 5
|
2021-05-16T11:00:13.000Z
|
2021-12-20T23:16:24.000Z
|
stm32/libraries/Klangstrom/examples/klang/extensions/ExampleTextToSpeechSAM/ExampleTextToSpeechSAM.ino
|
dennisppaul/klangstrom-arduino
|
d1f805b9813d1ec08b5b850abf1270fb037245d9
|
[
"CC0-1.0"
] | null | null | null |
//
// ExampleTextToSpeechSAM
//
#define KLANG_EXT_NODE_TEXT_TO_SPEECH_SAM
#include "KlangNodes.hpp"
using namespace klang;
using namespace klangstrom;
NodeDAC mDAC;
/*
* allocate buffer for pre-rendered voices use `get_used_buffer_length()` to get text length
* *after* text is rendered with `speak()`.
*/
NodeTextToSpeechSAM mTTS(46160);
void setup() {
Klang::connect(mTTS, Node::CH_OUT_SIGNAL, mDAC, NodeDAC::CH_IN_SIGNAL_LEFT);
mTTS.speak("/HAA5RGLOW MAY5N NAA5RMEY4 IHSD \x9b\x9b\0", true);
}
void audioblock(SIGNAL_TYPE* pOutputLeft, SIGNAL_TYPE* pOutputRight, SIGNAL_TYPE* pInputLeft, SIGNAL_TYPE* pInputRight) {
mDAC.process_frame(pOutputLeft, pOutputRight);
}
void event_receive(const EVENT_TYPE event, const float* data) {
switch (event) {
case EVENT_KEY_PRESSED:
handle_key_pressed(data[KEY]);
break;
case EVENT_MOUSE_PRESSED:
case EVENT_ENCODER_BUTTON_PRESSED:
if (data[INDEX] == ENCODER_00) {
mTTS.set_speed(100);
mTTS.set_pitch(96);
mTTS.speak("KLAH5NXSHDROW5M \x9b\x9b\0", true);
break;
} else if (data[INDEX] == ENCODER_01) {
mTTS.set_speed(72);
mTTS.set_pitch(64);
mTTS.speak("hello my name is");
break;
} else if (data[INDEX] == ENCODER_02) {
mTTS.set_speed(100);
mTTS.set_pitch(96);
mTTS.speak("klangstrom");
break;
}
}
}
void handle_key_pressed(int key) {
mTTS.speak_ascii(key);
}
| 28.491228
| 121
| 0.610837
|
3145eae5d5b972c6f1a8e7829fa6e45dac91ab93
| 5,533
|
ino
|
Arduino
|
EvilMousePrank_Sketch/EvilMousePrank_Sketch.ino
|
tdicola/EvilMousePrank
|
e8b97c22bcdb2aaba7e247123316c24ab187500a
|
[
"MIT"
] | 10
|
2015-04-28T08:06:37.000Z
|
2018-04-23T17:16:24.000Z
|
EvilMousePrank_Sketch/EvilMousePrank_Sketch.ino
|
tdicola/EvilMousePrank
|
e8b97c22bcdb2aaba7e247123316c24ab187500a
|
[
"MIT"
] | 1
|
2016-09-09T19:19:28.000Z
|
2016-09-09T19:19:28.000Z
|
EvilMousePrank_Sketch/EvilMousePrank_Sketch.ino
|
tdicola/EvilMousePrank
|
e8b97c22bcdb2aaba7e247123316c24ab187500a
|
[
"MIT"
] | 4
|
2016-05-03T18:33:15.000Z
|
2021-05-28T22:06:26.000Z
|
// Evil Mouse Prank for Arduino Yun
// Arduino Yun Sketch
// Copyright 2014 Tony DiCola (tony@tonydicola.com)
// Released under an MIT license (http://opensource.org/licenses/MIT)
// Scale factor applied to mouse X axis. Value of 1 is normal, -1 is inverted.
char mouseXScale = 1;
// Scale factor applied to mouse Y axis. Value of 1 is normal, -1 is inverted.
char mouseYScale = 1;
// Scale factor applied to mouse wheel axis. Value of 1 is normal, -1 is inverted.
char mouseWheelScale = 1;
// True/false if the mouse X and Y axis should transpose their values (this is SUPER disorienting!).
bool mouseXYFlipped = false;
// True/false if mouse left and right buttons should be flipped.
bool mouseLeftRightFlipped = false;
// True/false to enable sticky ball mouse emulation. When sticky ball emulation is on
// the X and Y axis will randomly refuse to move for short periods of time (to emulate
// an infuriatingly sticky old mechanical ball mouse).
bool emulateStickyBall = false;
// Internal state used by the sticky ball emulation:
bool stickyX = false;
bool stickyY = false;
unsigned long stickyPeriod = 0;
void setup() {
// Initialize Serial1, the port which is connected to the Linux processor. The EvilMousePrank.py
// script will send mouse events over Serial1 to the sketch.
// NOTE: When the Yun is booting up the Serial connection will be flooded with information from
// from the Linux boot process. To work around this wait 90 seconds, clearing the serial buffer
// every second. This is an ugly hack but unfortunately necessary. See this thread for more
// information:
// http://forum.arduino.cc/index.php?topic=191820.msg1436262#msg1436262
Serial1.begin(115200);
for (int i = 0; i < 90; ++i) {
delay(1000);
while (Serial1.available() > 0) {
Serial1.read();
}
}
Mouse.begin();
// Seed the random number generator with noise.
randomSeed(analogRead(0));
}
void loop() {
// Check if a command has been sent to the sketch.
// Each command is 2 bytes in length, the first byte is the command ID and the second
// is a signed byte value (which might be ignored by some commands).
if (Serial1.available() >= 2) {
// Read the command and value.
char command = Serial1.read();
char value = Serial1.read();
// Handle the command.
switch (command) {
case 'X': mouseX(value);
break;
case 'Y': mouseY(value);
break;
case 'W': mouseWheel(value);
break;
case 'L': mouseLeft(value);
break;
case 'R': mouseRight(value);
break;
case 'M': mouseMiddle(value);
break;
case 's': emulateStickyBall = true;
break;
case 'x': // Invert X axis.
mouseXScale = -1;
break;
case 'y': // Invert Y axis.
mouseYScale = -1;
break;
case 't': mouseXYFlipped = true;
break;
case 'f': mouseLeftRightFlipped = true;
break;
case 'r': reset();
break;
}
}
// Update sticky ball emulation state.
if (emulateStickyBall) {
// Check if sticky ball state should update.
if (millis() >= stickyPeriod) {
// Each axis has a 1/4 chance of going sticky.
int n = random(4);
if (n == 0) {
// Set X axis sticky.
stickyX = true;
stickyY = false;
}
else if (n == 1) {
// Set Y axis sticky.
stickyY = true;
stickyX = false;
}
else {
// Make no axis sticky.
stickyY = false;
stickyX = false;
}
// Pick a new random period of time between 500-1500ms for the stickyness to last.
stickyPeriod = millis() + random(500, 1500);
}
}
}
// Mouse X axis command handler.
void mouseX(char value) {
if (stickyX) {
// Do nothing if the axis is stuck.
return;
}
// Send a mouse movement that's scaled and on the appropriate axis.
if (!mouseXYFlipped) {
Mouse.move(mouseXScale*value, 0, 0);
}
else {
Mouse.move(0, mouseXScale*value, 0);
}
}
// Mouse Y axis command handler.
void mouseY(char value) {
if (stickyY) {
// Do nothing if the axis is stuck.
return;
}
// Send a mouse movement that's scaled and on the appropriate axis.
if (!mouseXYFlipped) {
Mouse.move(0, mouseYScale*value, 0);
}
else {
Mouse.move(mouseYScale*value, 0, 0);
}
}
// Mouse wheel axis command handler.
void mouseWheel(char value) {
Mouse.move(0, 0, mouseWheelScale*value);
}
// Mouse left button command handler.
void mouseLeft(char value) {
int button = mouseLeftRightFlipped ? MOUSE_RIGHT : MOUSE_LEFT;
if (value == 1) {
Mouse.press(button);
}
else if (value == 0) {
Mouse.release(button);
}
}
// Mouse right button command handler.
void mouseRight(char value) {
int button = mouseLeftRightFlipped ? MOUSE_LEFT : MOUSE_RIGHT;
if (value == 1) {
Mouse.press(button);
}
else if (value == 0) {
Mouse.release(button);
}
}
// Mouse middle button command handler.
void mouseMiddle(char value) {
if (value == 1) {
Mouse.press(MOUSE_MIDDLE);
}
else if (value == 0) {
Mouse.release(MOUSE_MIDDLE);
}
}
// Reset all the state back to normal mouse behavior.
void reset() {
mouseXScale = 1;
mouseYScale = 1;
mouseWheelScale = 1;
mouseXYFlipped = false;
mouseLeftRightFlipped = false;
emulateStickyBall = false;
stickyX = false;
stickyY = false;
}
| 28.817708
| 100
| 0.630219
|
71f07d45e26fdb53444d98dd5f5250fd1eabcca3
| 2,045
|
ino
|
Arduino
|
examples/ESP8266_WiFi/ESP8266_WiFi.ino
|
mgolu/ELMduino
|
4d103c85d0ab1d349fcaa215594b91f704b05606
|
[
"MIT"
] | null | null | null |
examples/ESP8266_WiFi/ESP8266_WiFi.ino
|
mgolu/ELMduino
|
4d103c85d0ab1d349fcaa215594b91f704b05606
|
[
"MIT"
] | null | null | null |
examples/ESP8266_WiFi/ESP8266_WiFi.ino
|
mgolu/ELMduino
|
4d103c85d0ab1d349fcaa215594b91f704b05606
|
[
"MIT"
] | null | null | null |
#include <ESP8266WiFi.h>
#include "ELMduino.h"
const char* ssid = "WiFi_OBDII";
const char* password = "your-password";
//IP Adress of your ELM327 Dongle
IPAddress server(192, 168, 0, 10);
WiFiClient client;
ELM327 myELM327;
uint32_t rpm = 0;
void setup()
{
Serial.begin(115200);
// Connecting to ELM327 WiFi
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.mode(WIFI_AP);
WiFi.begin(ssid);
// WiFi.begin(ssid, password); //Use this line if your ELM327 has a password protected WiFi
while (WiFi.status() != WL_CONNECTED)
{
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("Connected to Wifi");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
if (client.connect(server, 35000))
Serial.println("connected");
else
{
Serial.println("connection failed");
ESP.reset();
}
myELM327.begin(client);
}
void loop()
{
float tempRPM = myELM327.rpm();
if (myELM327.status == ELM_SUCCESS)
{
rpm = (uint32_t)tempRPM;
Serial.print("RPM: "); Serial.println(rpm);
}
else
printError();
}
void printError()
{
Serial.print("Received: ");
for (byte i = 0; i < myELM327.recBytes; i++)
Serial.write(myELM327.payload[i]);
Serial.println();
if (myELM327.status == ELM_SUCCESS)
Serial.println(F("\tELM_SUCCESS"));
else if (myELM327.status == ELM_NO_RESPONSE)
Serial.println(F("\tERROR: ELM_NO_RESPONSE"));
else if (myELM327.status == ELM_BUFFER_OVERFLOW)
Serial.println(F("\tERROR: ELM_BUFFER_OVERFLOW"));
else if (myELM327.status == ELM_UNABLE_TO_CONNECT)
Serial.println(F("\tERROR: ELM_UNABLE_TO_CONNECT"));
else if (myELM327.status == ELM_NO_DATA)
Serial.println(F("\tERROR: ELM_NO_DATA"));
else if (myELM327.status == ELM_STOPPED)
Serial.println(F("\tERROR: ELM_STOPPED"));
else if (myELM327.status == ELM_TIMEOUT)
Serial.println(F("\tERROR: ELM_TIMEOUT"));
else if (myELM327.status == ELM_TIMEOUT)
Serial.println(F("\tERROR: ELM_GENERAL_ERROR"));
delay(100);
}
| 21.989247
| 93
| 0.669927
|
e92f7a8403ebe214ca83de9a85981a2821725f15
| 633
|
ino
|
Arduino
|
ir_Tramsmitter/ir_Tramsmitter.ino
|
technonerdz/Arduino-RC-car
|
181dc96267295aec52d57f51dad0c043800d9643
|
[
"MIT"
] | null | null | null |
ir_Tramsmitter/ir_Tramsmitter.ino
|
technonerdz/Arduino-RC-car
|
181dc96267295aec52d57f51dad0c043800d9643
|
[
"MIT"
] | null | null | null |
ir_Tramsmitter/ir_Tramsmitter.ino
|
technonerdz/Arduino-RC-car
|
181dc96267295aec52d57f51dad0c043800d9643
|
[
"MIT"
] | null | null | null |
#include <IRremote.h>
#include <IRremoteInt.h>
IRsend irsend;
void setup()
{
Serial.begin(9600);
}
void loop()
{
for (int i = 0; i < 10; i++) {
int tosend = 0xa0 + i;
irsend.sendSony(tosend, 12);
delay(40);
}
// for (int i = 0; i < 10; i++) {
// int tosend = 0xb0 + i;
// irsend.sendSony(tosend, 12);
// delay(40);
// }
//
// for (int i = 0; i < 10; i++) {
// int tosend = 0xc0 + i;
// irsend.sendSony(tosend, 12);
// delay(40);
// }
//
// for (int i = 0; i < 10; i++) {
// int tosend = 0xd0 + i;
// irsend.sendSony(tosend, 12);
// delay(40);
// }
}
| 15.439024
| 36
| 0.472354
|
30cc25703d1a05aba3cfbbc4b278173913509787
| 9,417
|
ino
|
Arduino
|
sketches/Inverter1/Inverter1.ino
|
kikiloaw/openMicroInverter
|
ec59da5025b827a8f0295e4783c3738e667666cf
|
[
"MIT"
] | null | null | null |
sketches/Inverter1/Inverter1.ino
|
kikiloaw/openMicroInverter
|
ec59da5025b827a8f0295e4783c3738e667666cf
|
[
"MIT"
] | null | null | null |
sketches/Inverter1/Inverter1.ino
|
kikiloaw/openMicroInverter
|
ec59da5025b827a8f0295e4783c3738e667666cf
|
[
"MIT"
] | null | null | null |
/*
* File: Inverter.ino
* Purpose: openMicroInverter example project. This sketch establishes a voltage-mode inverter without output voltage control (open loop).
* Version: 1.0.1
* Date: 02-12-2019
*
* URL: https://github.com/MartinStokroos/openMicroInverter
*
* License: MIT License
*
* Copyright (c) M.Stokroos 2019
*
*
*
* This sketch has been tested with the openMicroInverter_dev hardware.
*
*/
#include <digitalWriteFast.h> // library for high performance digital reads and writes by jrraines
// see http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1267553811/0
// and http://code.google.com/p/digitalwritefast/
#include <TrueRMS.h> // https://github.com/MartinStokroos/TrueRMS
#include <PowerSys.h> // https://github.com/MartinStokroos/openMicroInverter
// switching mode:
//#define UNIPOL // unipolar switching
#define BIPOL // bipolar switching
//#define HYBRID // bipolar switching, bottom H-bridge=LF
#define LPERIOD 1000000 // loop period time in us. In this case 1s.
#define RMSWINDOW 20 // RMS window, number of samples used for the RMS calculation.
#define PIN_LED 13 // PLL locking status indicator LED
#define PIN_H_PWMA 9 // Timer1 OCR1A 10-bit PWM
#define PIN_H_PWMB 10 // Timer1 OCR1B 10-bit PWM
#define PIN_H_AHI 3 // H-bridge control pin
#define PIN_H_BHI 11 // H-bridge control pin
#define PIN_H_DIS 8 // enable inverter
#define PIN_GRID_RELAY 2 // output relay
#define PIN_DEBUG 4 // debugging output pin
//scaling calibration
const float outputVoltRange = 660.0; //Vp-p full scale.
const float outputCurrRange = 4.5; //Ap-p full scale.
const float vBattRange = 1.00; //Vbatt max, temporary used for magnitude control.
const float iBattRange = 10.00;
// ADC vars
volatile int adcVal;
volatile int adcMuxIdx = 0; // multiplexer index
// PWM DAC
unsigned int ndac_out; // DAC magnitude value
unsigned int pdac_out;
int dac_out;
// inverter
const float TD = 1/6000.0; //time step for f=6000 Hz
const float f0 = 50.0; // output frequency in Hz
// define instances for ac/dc voltage, current and power metering and DDS
Power2 outputMeas;
Average vBatt;
Average iBatt;
PowerControl outputWave;
unsigned long nextLoop;
// ******************************************************************
// Setup
// ******************************************************************
void setup(){
cli(); // enable interrupts
// initialize serial communications:
Serial.begin(115200);
pinMode(PIN_LED, OUTPUT);
pinMode(PIN_H_PWMA, OUTPUT);
pinMode(PIN_H_PWMB, OUTPUT);
pinMode(PIN_H_AHI, OUTPUT);
pinMode(PIN_H_BHI, OUTPUT);
pinMode(PIN_GRID_RELAY, OUTPUT);
pinMode(PIN_H_DIS, OUTPUT);
pinMode(PIN_DEBUG, OUTPUT);
// initialize ADC for continuous sampling mode
DIDR0 = 0x3F; // digital inputs disabled for ADC0D to ADC5D
bitSet(ADMUX, REFS0); // Select Vcc=5V as the ADC reference voltage
bitClear(ADMUX, REFS1);
bitClear(ADMUX, MUX0); // selecting ADC CH# 0
bitClear(ADMUX, MUX1);
bitClear(ADMUX, MUX2);
bitClear(ADMUX, MUX3);
bitSet(ADCSRA, ADEN); // AD-converter enabled
bitSet(ADCSRA, ADATE); // auto-trigger enabled
bitSet(ADCSRA, ADIE); // ADC interrupt enabled
bitSet(ADCSRA, ADPS0); // ADC clock prescaler set to 128
bitSet(ADCSRA, ADPS1);
bitSet(ADCSRA, ADPS2);
bitClear(ADCSRB, ACME); // Analog Comparator (ADC)Multiplexer enable OFF
bitClear(ADCSRB, ADTS0); // triggered by Timer/Counter1 Overflow
bitSet(ADCSRB, ADTS1);
bitSet(ADCSRB, ADTS2);
bitSet(ADCSRA, ADSC); // start conversion
/* TIMER1 configured for phase and frequency correct PWM-mode 8, top=ICR1 */
// prescaler = 1:
bitSet(TCCR1B, CS10);
bitClear(TCCR1B, CS11);
bitClear(TCCR1B, CS12);
// mode 8:
bitClear(TCCR1A, WGM10);
bitClear(TCCR1A, WGM11);
bitClear(TCCR1B, WGM12);
bitSet(TCCR1B, WGM13);
// top value. f_TIM1 = fclk/(2*N*TOP)
ICR1 = 0x0536; //0x0535, f=6kHz, min 0x03FF;
#ifdef UNIPOL
#define ICR1_OFFSET 0x09B;
digitalWriteFast(PIN_H_AHI, HIGH);
digitalWriteFast(PIN_H_BHI, HIGH);
bitClear(TCCR1A, COM1A0); // Compare Match PWM 10
bitSet(TCCR1A, COM1A1);
bitClear(TCCR1A, COM1B0); // Compare Match PWM 9
bitSet(TCCR1A, COM1B1);
#endif
#ifdef BIPOL
#define ICR1_OFFSET 0x09B;
digitalWriteFast(PIN_H_AHI, HIGH);
digitalWriteFast(PIN_H_BHI, HIGH);
bitClear(TCCR1A, COM1A0); // Compare Match PWM 10
bitSet(TCCR1A, COM1A1);
bitSet(TCCR1A, COM1B0); // Compare Match PWM9, inverted
bitSet(TCCR1A, COM1B1);
#endif
#ifdef HYBRID
#define ICR1_OFFSET 0x09B;
digitalWriteFast(PIN_H_AHI, LOW);
digitalWriteFast(PIN_H_BHI, LOW);
bitSet(TCCR1A, COM1A0); // Compare Match PWM 10
bitSet(TCCR1A, COM1A1);
bitSet(TCCR1A, COM1B0); // Compare Match PWM 9
bitSet(TCCR1A, COM1B1);
#endif
// enable timer compare interrupt
bitSet(TIMSK1, TOIE1); // enable Timer1 Interrupt
outputMeas.begin(outputCurrRange, outputVoltRange, RMSWINDOW, ADC_10BIT, BLR_ON, CNT_SCAN);
vBatt.begin(vBattRange, RMSWINDOW, ADC_10BIT, CNT_SCAN);
iBatt.begin(iBattRange, RMSWINDOW, ADC_10BIT, CNT_SCAN);
outputMeas.start();
vBatt.start();
iBatt.start();
outputWave.osgBegin(f0, TD); // initilize the DDS (frequency, startphase, update period time)
sei(); // enable interrupts
nextLoop = micros() + LPERIOD; // Set the loop timer variable for the next loop interval.
}
// ******************************************************************
// Main loop
// ******************************************************************
void loop(){
digitalWriteFast(PIN_LED, HIGH);
vBatt.publish();
iBatt.publish();
outputMeas.publish();
Serial.print(outputMeas.rmsVal2, 1); // print the RMS output voltage
Serial.print(", ");
Serial.print(outputMeas.rmsVal1, 1); // print the RMS output current
Serial.print(", ");
Serial.print(outputMeas.apparentPwr, 0); // print the RMS output VA's
Serial.print(", ");
Serial.print(outputMeas.realPwr, 0); // print the RMS output Watts
Serial.print(", ");
Serial.print(vBatt.average, 1);
Serial.print(", ");
Serial.println(iBatt.average, 1);
while(nextLoop > micros()); // wait until the end of the time interval
nextLoop += LPERIOD; // set next loop time at current time + LOOP_PERIOD
digitalWriteFast(PIN_LED, LOW);
}
/* ******************************************************************
* ADC ISR. ADC is triggered by Timer1.
* *******************************************************************/
ISR(ADC_vect){
digitalWriteFast(PIN_DEBUG, HIGH);
// read the current ADC input channel
adcVal=ADCL; // store low byte
adcVal+=ADCH<<8; // store high byte
switch (adcMuxIdx) {
case 0:
//sample the grid voltage
break;
case 1: //sample the inverter current
//outputMeas.update1(adcVal);
break;
case 2: //sample the inverter voltage
//outputMeas.update2(adcVal);
break;
case 3: // sample the battery current
//iBatt.update(adcVal);
break;
case 4: //sample the battery voltage
//vBatt.update(adcVal);
break;
case 5:
break;
// default:
}
adcMuxIdx++;
if (adcMuxIdx > 5){
adcMuxIdx = 0;
}
ADMUX = (ADMUX & B11110000) | adcMuxIdx; // set the ADC-MUX channel for the next call
digitalWriteFast(PIN_DEBUG, LOW);
}
/* ******************************************************************
* Timer1 ISR running at 6000Hz
*********************************************************************/
ISR(TIMER1_OVF_vect) {
// generate the reference sin wave with DDS.
outputWave.osgUpdate(0, 0);
#ifdef UNIPOL
// complementary sin waves drive both legs in H-bridge. High-side and low-side are PWM-switched. AHI=5V and BHI=5V.
// (see HIP4082 application note; LF switched inverter ALI//BHI (pin4,2) and AHI//BLI (7,3) )
pdac_out = outputWave.rcos + 0x1FF; //make unsigned, 10 bit range
ndac_out = (~pdac_out) & 0x3FF; //invert for n-channel.
pdac_out += ICR1_OFFSET; // add offset to center between the BOTTOM to TOP value range of the timer.
ndac_out += ICR1_OFFSET;
// write to PWM output registers A&B (10bit).
OCR1AH = pdac_out>>8; //MSB
OCR1AL = pdac_out; //LSB
//inverted output channel (dead-time correction inside the H-bridge driver HIP4082):
OCR1BH = ndac_out>>8; //MSB
OCR1BL = ndac_out; //LSB
#endif
#ifdef BIPOL
dac_out = outputWave.rcos;
// complementary gate drives in both legs of the H-bridge. AHI=5V and BHI=5V.
dac_out += 0x1FF;
dac_out += ICR1_OFFSET;
OCR1AH = dac_out >> 8; // top 8 bits
OCR1AL = dac_out; //bottom 8 bits
OCR1BH = OCR1AH; //Signal inverted with the output compare setting above.
OCR1BL = OCR1AL;
#endif
#ifdef HYBRID // LF+PWM dive. Not optimal yet... Reference wave should be half wave with 10bit or more amplitude range.
dac_out = outputWave.rcos;
// write magnitude data to PWM output registers A&B (10bit).
if (dac_out >= 0) {
digitalWriteFast(PIN_H_AHI, LOW);
digitalWriteFast(PIN_H_BHI, HIGH);
dac_out = dac_out<<1; //times 2
OCR1AH = dac_out>>8; // top 8 bits
OCR1AL = dac_out; // bottom 8 bits
}
else {
digitalWriteFast(PIN_H_BHI, LOW);
digitalWriteFast(PIN_H_AHI, HIGH);
dac_out = (-dac_out)<<1; //times 2
OCR1BH = dac_out>>8; // top 8 bits
OCR1BL = dac_out; // bottom 8 bits
}
#endif
}
| 31.600671
| 138
| 0.648827
|
7db2d4be67afd335079cae13fede075fdd7ce79c
| 741
|
ino
|
Arduino
|
remote_drawing_wifi/wifi.ino
|
raphaelchampeimont/arduino_remote_drawing
|
82599017bf0fb7ba319733eca5db80427cd5fd60
|
[
"MIT"
] | 1
|
2022-03-16T11:38:09.000Z
|
2022-03-16T11:38:09.000Z
|
remote_drawing_wifi/wifi.ino
|
raphaelchampeimont/arduino_remote_drawing
|
82599017bf0fb7ba319733eca5db80427cd5fd60
|
[
"MIT"
] | 6
|
2021-08-02T09:59:03.000Z
|
2022-01-28T11:41:38.000Z
|
remote_drawing_wifi/wifi.ino
|
raphaelchampeimont/arduino_remote_drawing
|
82599017bf0fb7ba319733eca5db80427cd5fd60
|
[
"MIT"
] | null | null | null |
#include <SPI.h>
#include <WiFiNINA.h>
#include "wifi.h"
#include "secrets.h"
#include "serial_com.h"
#include "system.h"
void initWifi() {
// check for the WiFi module:
if (WiFi.status() == WL_NO_MODULE) {
fatalError("INTERNAL ERROR: Communication with WiFi hardware failed!");
}
String fv = WiFi.firmwareVersion();
if (fv < WIFI_FIRMWARE_LATEST_VERSION) {
Serial.println("Please upgrade the firmware");
}
WiFi.lowPowerMode();
sendStatusMessageFormat("Trying to connect to \"%s\" wifi network...", WIFI_NAME);
if (WiFi.begin(WIFI_NAME, WIFI_PASSWORD) != WL_CONNECTED) {
fatalError("Connection to Wifi network \"%s\" failed", WIFI_NAME);
}
sendStatusMessage("Connection to wifi OK.");
delay(1000);
}
| 25.551724
| 84
| 0.690958
|
9ff0daa602255916e9c89a585d8059de5ff0d992
| 1,292
|
ino
|
Arduino
|
examples/PID_POn_DOn_Error_Measurement/PID_POn_DOn_Error_Measurement.ino
|
lbussy/QuickPID
|
11a10e1375e7a3b3824e6af4c23d7aa0bd1266e9
|
[
"MIT"
] | 56
|
2021-02-01T17:55:00.000Z
|
2022-03-29T17:40:59.000Z
|
examples/PID_POn_DOn_Error_Measurement/PID_POn_DOn_Error_Measurement.ino
|
lbussy/QuickPID
|
11a10e1375e7a3b3824e6af4c23d7aa0bd1266e9
|
[
"MIT"
] | 37
|
2021-03-20T17:16:08.000Z
|
2022-03-30T17:56:06.000Z
|
examples/PID_POn_DOn_Error_Measurement/PID_POn_DOn_Error_Measurement.ino
|
lbussy/QuickPID
|
11a10e1375e7a3b3824e6af4c23d7aa0bd1266e9
|
[
"MIT"
] | 25
|
2021-03-30T13:30:40.000Z
|
2022-03-29T17:41:05.000Z
|
/**************************************************************************************
Proportional and Derivative on the ratio of Error to Measurement Example
Increasing the proportional on measurement setting will make the output move more
smoothly when the setpoint is changed. Also, it can eliminate overshoot.
Decreasing the derivative on measurement adds more derivative on error. This reduces
reduce overshoot but may increase output spikes. Adjust to suit your requirements.
**************************************************************************************/
#include "QuickPID.h"
//Define Variables we'll be connecting to
float Setpoint, Input, Output;
float POn = 1.0; // proportional on Error to Measurement ratio (0.0-1.0), default = 1.0
float DOn = 0.0; // derivative on Error to Measurement ratio (0.0-1.0), default = 0.0
//Specify the links and initial tuning parameters
QuickPID myQuickPID(&Input, &Output, &Setpoint, 2, 5, 1, POn, DOn, QuickPID::DIRECT);
void setup()
{
//initialize the variables we're linked to
Input = myQuickPID.analogReadFast(0);
Setpoint = 100;
//turn the PID on
myQuickPID.SetMode(QuickPID::AUTOMATIC);
}
void loop()
{
Input = myQuickPID.analogReadFast(0);
myQuickPID.Compute();
analogWrite(3, Output);
}
| 36.914286
| 89
| 0.640093
|
abdb0f5da7b2cbd29ecba2232317af03dace444b
| 184
|
ino
|
Arduino
|
show_serial_data.ino
|
T00ManySecrets/water-gprs-temp-v2
|
61b771244dfb2bf2e08181e382df9a9dcbfa917c
|
[
"Apache-2.0"
] | null | null | null |
show_serial_data.ino
|
T00ManySecrets/water-gprs-temp-v2
|
61b771244dfb2bf2e08181e382df9a9dcbfa917c
|
[
"Apache-2.0"
] | null | null | null |
show_serial_data.ino
|
T00ManySecrets/water-gprs-temp-v2
|
61b771244dfb2bf2e08181e382df9a9dcbfa917c
|
[
"Apache-2.0"
] | null | null | null |
void ShowSerialData()
{
unsigned long entry = millis();
while ( A6board.available() != 0 && millis() - entry < SERIALTIMEOUT)
Serial.println(A6board.readStringUntil('\n'));
}
| 26.285714
| 71
| 0.668478
|
27c982b0df334977d2e98bb17097b29e8ccf7ea1
| 4,089
|
ino
|
Arduino
|
schedule.ino
|
fontesrp/home_energy_control_water_system
|
63fc2c46622fbbbb0c14007ea4dba13ca2e0dfd2
|
[
"MIT"
] | null | null | null |
schedule.ino
|
fontesrp/home_energy_control_water_system
|
63fc2c46622fbbbb0c14007ea4dba13ca2e0dfd2
|
[
"MIT"
] | null | null | null |
schedule.ino
|
fontesrp/home_energy_control_water_system
|
63fc2c46622fbbbb0c14007ea4dba13ca2e0dfd2
|
[
"MIT"
] | null | null | null |
#include "schedule.h"
static int treatIndex(int index) {
if (index < 0) {
index = SCHEDULE_DATES_QTT - 1;
} else if (index >= SCHEDULE_DATES_QTT) {
index = 0;
}
return index;
}
static int findTimeIndex(int searchWeekday, int searchHour, int searchMinute, int index) {
if (searchWeekday < scheduleDates[index].weekday) {
index--;
} else if (searchWeekday > scheduleDates[index].weekday) {
index = treatIndex(++index);
index = findTimeIndex(searchWeekday, searchHour, searchMinute, index);
} else if (searchHour < scheduleDates[index].hour) {
index--;
} else if (searchHour > scheduleDates[index].hour) {
index = treatIndex(++index);
index = findTimeIndex(searchWeekday, searchHour, searchMinute, index);
} else if (searchMinute < scheduleDates[index].minute) {
index--;
} else if (searchMinute > scheduleDates[index].minute) {
index = treatIndex(++index);
index = findTimeIndex(searchWeekday, searchHour, searchMinute, index);
}
return treatIndex(index);
}
static int findIndex(int searchWeekday, int searchHour, int searchMinute) {
int i, index = 0;
// This loop will return the first schedule for the searched weekday, which should have state CIRCUIT_OFF
for (i = 0; i < SCHEDULE_DATES_QTT; i++) {
if (scheduleDates[i].weekday == searchWeekday) {
index = i;
i = SCHEDULE_DATES_QTT;
}
}
if (i == SCHEDULE_DATES_QTT) {
return -1;
} else {
return findTimeIndex(searchWeekday, searchHour, searchMinute, index);
}
}
static void setScheduleDates() {
// Must be organized in ascending order from Sunday 00:00, always with one CIRCUIT_ON for every CIRCUIT_OFF in the same day
scheduleDates[0].weekday = 1; // Sunday 01:00 OFF
scheduleDates[0].hour = 1;
scheduleDates[0].minute = 0;
scheduleDates[0].state = CIRCUIT_OFF;
scheduleDates[1].weekday = 1; // Sunday 05:00 ON
scheduleDates[1].hour = 5;
scheduleDates[1].minute = 0;
scheduleDates[1].state = CIRCUIT_ON;
scheduleDates[2].weekday = 2; // Monday 01:00 OFF
scheduleDates[2].hour = 1;
scheduleDates[2].minute = 0;
scheduleDates[2].state = CIRCUIT_OFF;
scheduleDates[3].weekday = 2; // Monday 04:00 ON
scheduleDates[3].hour = 4;
scheduleDates[3].minute = 0;
scheduleDates[3].state = CIRCUIT_ON;
scheduleDates[4].weekday = 3; // Tuesday 01:00 OFF
scheduleDates[4].hour = 1;
scheduleDates[4].minute = 0;
scheduleDates[4].state = CIRCUIT_OFF;
scheduleDates[5].weekday = 3; // Tuesday 04:00 ON
scheduleDates[5].hour = 4;
scheduleDates[5].minute = 0;
scheduleDates[5].state = CIRCUIT_ON;
scheduleDates[6].weekday = 4; // Wednesday 01:00 OFF
scheduleDates[6].hour = 1;
scheduleDates[6].minute = 0;
scheduleDates[6].state = CIRCUIT_OFF;
scheduleDates[7].weekday = 4; // Wednesday 04:00 ON
scheduleDates[7].hour = 4;
scheduleDates[7].minute = 0;
scheduleDates[7].state = CIRCUIT_ON;
scheduleDates[8].weekday = 5; // Thursday 01:00 OFF
scheduleDates[8].hour = 1;
scheduleDates[8].minute = 0;
scheduleDates[8].state = CIRCUIT_OFF;
scheduleDates[9].weekday = 5; // Thursday 04:00 ON
scheduleDates[9].hour = 4;
scheduleDates[9].minute = 0;
scheduleDates[9].state = CIRCUIT_ON;
scheduleDates[10].weekday = 6; // Friday 01:00 OFF
scheduleDates[10].hour = 1;
scheduleDates[10].minute = 0;
scheduleDates[10].state = CIRCUIT_OFF;
scheduleDates[11].weekday = 6; // Friday 04:00 ON
scheduleDates[11].hour = 4;
scheduleDates[11].minute = 0;
scheduleDates[11].state = CIRCUIT_ON;
scheduleDates[12].weekday = 7; // Saturday 01:00 OFF
scheduleDates[12].hour = 1;
scheduleDates[12].minute = 0;
scheduleDates[12].state = CIRCUIT_OFF;
scheduleDates[13].weekday = 7; // Saturday 05:00 ON
scheduleDates[13].hour = 5;
scheduleDates[13].minute = 0;
scheduleDates[13].state = CIRCUIT_ON;
}
char getScheduledState(int currentWeekday, int currentHour, int currentMinute) {
int scheduleIndex;
if (!scheduleSet) {
setScheduleDates();
scheduleSet = 1;
}
scheduleIndex = findIndex(currentWeekday, currentHour, currentMinute);
if (scheduleIndex == -1) {
return 123;
} else {
return scheduleDates[scheduleIndex].state;
}
}
| 27.628378
| 124
| 0.711176
|
3550299ca49814518daa26f650ea9ff70cd4829c
| 1,519
|
ino
|
Arduino
|
arduino/left_odom/left_odom.ino
|
joeyzhu00/FusionAD
|
7c912e399b9fcfa657d623f74be64921fc1a11ac
|
[
"MIT"
] | 33
|
2018-06-03T19:45:42.000Z
|
2022-02-17T09:18:11.000Z
|
arduino/left_odom/left_odom.ino
|
joeyzhu00/FusionAD
|
7c912e399b9fcfa657d623f74be64921fc1a11ac
|
[
"MIT"
] | 167
|
2018-05-17T03:48:11.000Z
|
2019-04-30T21:57:01.000Z
|
arduino/left_odom/left_odom.ino
|
joeyzhu00/FusionAD
|
7c912e399b9fcfa657d623f74be64921fc1a11ac
|
[
"MIT"
] | 26
|
2018-07-04T04:32:54.000Z
|
2022-02-22T10:10:49.000Z
|
#include <ros.h>
#include <std_msgs/Int32.h>
ros::NodeHandle nh;
std_msgs::Int32 left_odometry_feedback;
// library for high performance reads and writes by jrraines
// see http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1267553811/0
// and http://code.google.com/p/digitalwritefast/
#include <digitalWriteFast.h>
ros::Publisher left_odometry_publisher("/localization/left_encoder_reading", &left_odometry_feedback);
// Left encoder
// Red - 5V
// Black - GND
const int left_encoder_a = 2; // Green - pin 2 - Digital
const int left_encoder_b = 3; // White - pin 3 - Digital
long left_encoder = 0;
void setup()
{
// set the baud rate at 115200 baud
nh.getHardware()->setBaud(115200);
// initialize the ros node
nh.initNode();
nh.advertise(left_odometry_publisher);
// Quadrature left_encoders
// Left left_encoder
pinMode(left_encoder_a, INPUT_PULLUP);
pinMode(left_encoder_b, INPUT_PULLUP);
attachInterrupt(0, left_encoderPinChangeA, RISING);
attachInterrupt(1, left_encoderPinChangeB, RISING);
}
void loop()
{
nh.spinOnce();
left_odometry_feedback.data = left_encoder;
left_odometry_publisher.publish(&left_odometry_feedback);
delay(20);
}
// Interrupt service routines for the left motor's quadrature left_encoder
void left_encoderPinChangeA()
{
left_encoder += digitalReadFast(left_encoder_a) == digitalReadFast(left_encoder_b) ? -1 : 1;
}
void left_encoderPinChangeB()
{
left_encoder += digitalReadFast(left_encoder_a) != digitalReadFast(left_encoder_b) ? -1 : 1;
}
| 25.745763
| 102
| 0.751152
|
6a99b869f35154540c69684fcc6960df608e554e
| 151
|
ino
|
Arduino
|
libraries/ap_inertialsensor/examples/MPU_6000/MPU_6000.ino
|
HARSHAL-IITB/IITBQUAD
|
17e00ed00f8a57335524374d12f447d045a42c6a
|
[
"MIT"
] | null | null | null |
libraries/ap_inertialsensor/examples/MPU_6000/MPU_6000.ino
|
HARSHAL-IITB/IITBQUAD
|
17e00ed00f8a57335524374d12f447d045a42c6a
|
[
"MIT"
] | null | null | null |
libraries/ap_inertialsensor/examples/MPU_6000/MPU_6000.ino
|
HARSHAL-IITB/IITBQUAD
|
17e00ed00f8a57335524374d12f447d045a42c6a
|
[
"MIT"
] | null | null | null |
#include "MPU6000.h"
//#include "Platform_MPU6000.h"
void setup()
{
MPU6000_Init();
Serial.begin(115200);
}
void loop()
{
MPU6000_Read();
}
| 9.4375
| 31
| 0.642384
|
996c62e9aa41bc0f67b078abe1a06743470383d7
| 5,031
|
ino
|
Arduino
|
libraries/RFM12B/Examples/LED_Control_Gateway/LED_Control_Gateway.ino
|
brulejr/sketchbook
|
0d8d4c5dd638bb9ba861b700fb0a0af2055c01d5
|
[
"MIT"
] | null | null | null |
libraries/RFM12B/Examples/LED_Control_Gateway/LED_Control_Gateway.ino
|
brulejr/sketchbook
|
0d8d4c5dd638bb9ba861b700fb0a0af2055c01d5
|
[
"MIT"
] | null | null | null |
libraries/RFM12B/Examples/LED_Control_Gateway/LED_Control_Gateway.ino
|
brulejr/sketchbook
|
0d8d4c5dd638bb9ba861b700fb0a0af2055c01d5
|
[
"MIT"
] | null | null | null |
/*
* Copyright (c) 2013 by Felix Rusu <felix@lowpowerlab.com>
*
* This file is free software; you can redistribute it and/or modify
* it under the terms of either the GNU General Public License version 2
* or the GNU Lesser General Public License version 2.1, both as
* published by the Free Software Foundation.
*/
// This is a GATEWAY sketch (LEDControl_Gateway) for a Moteino that can act as
// a coordinator to control the LEDs on other Moteinos loaded
// with the corresponding NODE sketches (LEDControl_Node)
// Designed by Felix Rusu (felix@lowpowerlab.com), www.LowPowerLab.com
// The LEDs on the endpoint Moteinos can be controlled as follows. In the GATEWAY's serial terminal:
// Type a node ID in the rage [2-9] to set the target node
// Type a LED mode [b,p,o] - blink, pulse, off
// Type a speed for the LED action [s,m,f] - slow, medium, fast
// Hit [ENTER] to send request to target
// The target Moteino receives the message and applies the requested LED mode and speed
#include <RFM12B.h>
#define NETWORKID 100
#define NODEID 1 // network ID used for this unit
#define KEY "ABCDABCDABCDABCD" //(16 bytes of your choice - keep the same on all encrypted nodes)
#define REQUESTACK true // whether to request ACKs for sent messages
#define ACK_TIME 50 // # of ms to wait for an ack
#define SERIAL_BAUD 115200
#define LED 9
uint8_t input;
RFM12B radio;
char mode = 'b'; //mode : 'b' = blinking, 'p' = pulsing, 'o' = 'off'
char theSpeed = 'm'; //speed : 's' = slow, 'm' = medium, 'f' = 'fast'
byte nodeId = 2; //node to send message to
char * sendBuf="x:y"; //format is MODE:SPEED
void displayMenu(boolean includeHeader=true)
{
if (includeHeader)
{
Serial.println("******************************************************************");
Serial.println("* Node blinking/pulsing program *");
}
Serial.println("******************************************************************");
Serial.println("* [2 (default) to 9] - change target node ID *");
Serial.println("* [b=BLINK (default), p=PULSE, o=OFF] - change target LED mode *");
Serial.println("* [s=SLOW, m=MEDIUM (default), f=FAST] - change target LED speed *");
Serial.println("* [ENTER] - send request to target *");
Serial.println("******************************************************************\n");
}
void setup()
{
pinMode(LED, OUTPUT);
radio.Initialize(NODEID, RF12_915MHZ, NETWORKID);
radio.Encrypt((uint8_t*)KEY);
Serial.begin(SERIAL_BAUD);
displayMenu();
}
void loop()
{
//check for serial input (from 2-9, to correspond to node IDs [2,9])
if (Serial.available() > 0) {
input = Serial.read();
if (input == 'p' || input == 'b' || input == 'o')
{
Serial.print("Switched mode to [" );
Serial.print(input == 'p' ? "PULSE" : input == 'b' ? "BLINK" : "OFF");
Serial.println("]...");
mode = input;
}
else if (input == 's' || input == 'm' || input == 'f')
{
Serial.print("Switched speed to [" );
Serial.print(input == 's' ? "SLOW" : input == 'm' ? "MEDIUM" : "FAST");
Serial.println("]...");
theSpeed = input;
}
else if (input >= '2' && input <= '9') //[2 to 9]
{
nodeId = input-48;
Serial.print("Switched to node [" );
Serial.print(nodeId);
Serial.println("]...\n");
}
else if (input == 13) //ENTER key pressed, send message with existing data (mode, nodeid)
sendMessage();
else
{
Serial.println("Invalid input, try again:\n");
displayMenu(false);
}
}
//pass any received RF message to serial
if (radio.ReceiveComplete())
{
if (radio.CRCPass())
{
digitalWrite(LED,1);
Serial.print('[');Serial.print(radio.GetSender(), DEC);Serial.print("] ");
for (byte i = 0; i < *radio.DataLen; i++)
Serial.print((char)radio.Data[i]);
if (radio.ACKRequested())
{
radio.SendACK();
Serial.print(" - ACK sent");
}
delay(5);
digitalWrite(LED,0);
}
else Serial.print("BAD-CRC");
Serial.println();
}
}
void sendMessage()
{
sprintf(sendBuf, "%c:%c", mode, theSpeed);
radio.Send(nodeId, sendBuf, 3, REQUESTACK);
Serial.print("Request sent ");
Serial.print(nodeId);
Serial.print(":");
Serial.print(mode=='b'?"BLINK":mode=='p'?"PULSE":"OFF");
if (mode!='o')
{
Serial.print(":");
Serial.print(theSpeed=='s'?"SLOW":theSpeed=='m'?"MEDIUM":"FAST");
}
Serial.println(waitForAck() ? " (ACK OK)" : "(no ACK reply)");
Blink(LED, 5);
}
// wait up to ACK_TIME for proper ACK, return true if received
static bool waitForAck() {
long now = millis();
while (millis() - now <= ACK_TIME)
if (radio.ACKReceived(nodeId))
return true;
return false;
}
void Blink(byte PIN, byte DELAY_MS)
{
pinMode(PIN, OUTPUT);
digitalWrite(PIN,HIGH);
delay(DELAY_MS);
digitalWrite(PIN,LOW);
}
| 32.458065
| 101
| 0.581395
|
cf1812f31b960efa863a7c021f5a7e6d1844659f
| 672
|
ino
|
Arduino
|
software/acurite5in1/PyComLopy4/lopy4_01/src/BMP180/examples/ReadChipID/ReadChipID.ino
|
marcorainone/WsLoraTransponder
|
b4fbf69fe3523b739477caa63d71ef88dc42901e
|
[
"MIT"
] | 1
|
2020-01-09T10:41:05.000Z
|
2020-01-09T10:41:05.000Z
|
software/lacrossews2300/BSFranceLora32u4II/bsf32u4_01/src/BMP180/examples/ReadChipID/ReadChipID.ino
|
marcorainone/WsLoraTransponder
|
b4fbf69fe3523b739477caa63d71ef88dc42901e
|
[
"MIT"
] | null | null | null |
software/lacrossews2300/BSFranceLora32u4II/bsf32u4_01/src/BMP180/examples/ReadChipID/ReadChipID.ino
|
marcorainone/WsLoraTransponder
|
b4fbf69fe3523b739477caa63d71ef88dc42901e
|
[
"MIT"
] | null | null | null |
/**
*
* ReadChipID.ino
*
* Written by Christian Paul, 2014
*
* Reads the Chip-ID Register.
* This muste be 0x55.
*
*/
#include <Wire.h>
void setup()
{
// welcome
Serial.begin(9600);
Serial.println("Read BMP180's ID");
Serial.println("must be 0x55 ...");
Serial.println();
// select register
Wire.begin();
Wire.beginTransmission(0x77);
Wire.write(0xD0);
Wire.endTransmission();
// read value
Wire.beginTransmission(0x77);
Wire.requestFrom(0x77, 1);
byte b = Wire.read();
Wire.endTransmission();
// output
Serial.print("ID is: 0x");
Serial.println(b, HEX);
}
void loop() {}
| 14.608696
| 38
| 0.587798
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.