Skip to content

Instantly share code, notes, and snippets.

void sonar()
{
float duration, distance;
digitalWrite(trig, HIGH);
delayMicroseconds(100);
digitalWrite(trig, LOW);//change trig pinmode to spark the signal
duration = pulseIn (echo, HIGH);// the duration of state of echo remaining HIGH
distance = duration/58;// 58 is from (duration/2)/29
@Ryanhu1015
Ryanhu1015 / UNO_master_transmit.cpp
Created June 25, 2017 04:51
UNO_master_transmit
#include <Wire.h>
#include <Colorduino.h>
byte number6[4][8] = {{0,0,0,0,0,0,0,0},{1,0,0,1,1,1,1,0},{1,0,0,1,0,0,1,0},{1,1,1,1,1,1,1,0}};
void setup()
{
//skip this part
}
void loop()
{
@Ryanhu1015
Ryanhu1015 / Colorduino_slave_readData.cpp
Created June 25, 2017 05:08
Colorduino_slave_readData
byte received[8][8];
void setup()
{
//skip this part
}
void loop()
{
for (byte x = 0; x < 8; x++)
{
for (byte y = 0; y < 8; y++)
unsigned long timeNow = 0;
unsigned long timeLast = 0;
int seconds = 0;
int minutes = 0;
int hours = 0;
int days = 0;
timeNow = millis()/1000;// millis is the function i have mentioned above
seconds = timeNow - timeLast;
IPAddress timeServerIP; // time.nist.gov NTP server address
const char *ntpServerName = "tick.stdtime.gov.tw";// this is one of the NTP server
const int NTP_PACKET_SIZE = 48;
byte packetBuffer[NTP_PACKET_SIZE];
WiFiUDP udp;
unsigned long sendNTPpacket(IPAddress &address)
{
@Ryanhu1015
Ryanhu1015 / interrupt_countingTime.cpp
Last active July 15, 2017 15:07
interrupt_countingTime
extern "C"
{
#include "user_interface.h"
}
os_timer_t myTimer;
void user_init(void) // the function will be set in setup to trigger the ISR function
{
os_timer_setfn(&myTimer, timerCallback, NULL);
@Ryanhu1015
Ryanhu1015 / NTPserver_alternative.cpp
Last active July 29, 2017 15:37
NTPserver_alternative
//there are three option
char *ntpServerName = "tick.stdtime.gov.tw";
char *ntpServerName2 = "clock.stdtime.gov.tw";
char *ntpServerName3 = "time.stdtime.gov.tw";
void setup()
{
//.skip this part
//.
//.
@Ryanhu1015
Ryanhu1015 / stepping_motor.cpp
Created December 10, 2017 15:31
stepping_motor.cpp
#define EN 8 // state LOW works
#define X_DIR 5
#define Y_DIR 6
#define X_STP 2
#define Y_STP 3
void setup() {
Serial.begin(115200);
pinMode(X_DIR, OUTPUT); //the initail pin mode of stepping motor
pinMode(X_STP, OUTPUT);
@Ryanhu1015
Ryanhu1015 / steppinpMotor.cpp
Created December 31, 2017 17:44
steppingMotor.cpp
void steppingMotor()
{
digitalWrite(X_STP, HIGH);
digitalWrite(Y_STP, HIGH);
delayMicroseconds(1);
digitalWrite(X_STP, LOW);
digitalWrite(Y_STP, LOW);
}
@Ryanhu1015
Ryanhu1015 / noInterrupt.cpp
Created January 20, 2018 17:23
noInterrupt.cpp
long record = 0;
byte rightEchoState;
byte lastRightState = LOW;
float awayFromRight;
void loop(){
record++;
rightStateChange();
}