Skip to content

Instantly share code, notes, and snippets.

View 7-seg-port-manip.ino
// Bit patterns in order with segments a, b, c, d, e, f, g where g is LSB and MSB is just unused.
byte digits[] = {0b01111110 , 0b00110000, 0b01101101, 0b1111001, 0b00110011, 0b01011011, 0b01011111, 0b01110000, 0b01111111, 0b01111011};
// Let's assume that the segments are on pins 3 through 9, so it's the top 5 bits of PORTD and the bottom 2 bits of PORTB
// They're in order so segment a is connected to pin 9 and segment g is connected to pin 3.
void displayNumber(byte aNumber) {
View Interrupt Encoder Example
// Code compiles but is untested
// In reality it would be too slow
// But it is easier to understand the
// concept here with digitalRead than
// it is with diret port reads
// I have used the same code written
// with port reads many times to read
// encoders. It works.
View PCINT MultiEncoder
// Encoders connected to PORTC
// The First encoder is on pins 0 and 2
// Second encoder is on pins 1 and 3
// So the A pins are together on 0 and 1
// B pins on 2 and 3
int printInterval = 500;
volatile int encoderCount[2] = {0, 0};
View gist:a8fe8ce167f47801915875e242fff62f
WiFiServer server(1234);
WiFiClient client;
void setupWiFi() {
Serial.println("Setting Up WiFi");
WiFi.mode(WIFI_STA);
IPAddress ipa(192, 168, 1, 75);
// IPAddress dns(192, 168, 1, 1);
IPAddress gate(192, 168, 1, 1);
@delta-G
delta-G / SerialServo.cpp
Created Jun 6, 2016
UNO code for robot
View SerialServo.cpp
#include "SerialServo.h"
int pos = 0;
int servo = 0;
boolean reading = false;
boolean gotServo = false;
Servo servos[6];
View espwifi.cpp
// Do not remove the include below
#include "espwifi.h"
#define dirA D3
#define dirB D4
#define enA D1
#define enB D2
WiFiServer server(1234);
WiFiClient client;
@delta-G
delta-G / ControlGUI.java
Created Jun 6, 2016
Part of Robot Control
View ControlGUI.java
import java.awt.Event;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;
import java.net.UnknownHostException;
View 7 segment display.ino
byte digits[] = {0b1111110 , 0b0110000, 0b1101101, 0b1111001, 0b0110011, 0b1011011, 0b1011111, 0b1110000, 0b1111111, 0b1111011};
// pins to segments g,f,e,d,c,b,a
byte pins[] = {3,4,5,6,7,8,9};
void displayNumber(int aNumber) {
for (int i = 0; i < 7; i++) {
digitalWrite(pins[i], digits[aNumber] & (1 << i));
}
}
View gist:8aae98ae76faeee1d9cb
int buttonState = HIGH;
boolean buttonPressed = false;
void pollButton() {
static int lastState = HIGH;
static unsigned long pressTime = 0;
int curState = digitalRead(BUTTON_PIN);
if (curState != lastState) {
pressTime = millis();
View better_countdown.ino
#define SEC_PER_MIN (60)
#define SEC_PER_HOUR (60ul * 60)
#define SEC_PER_DAY (24ul * 60 * 60)
unsigned long countdownTime = 0;
void setup(){