cleaned up the repository and renamed stuff
This commit is contained in:
parent
6220336f38
commit
eba2f28953
47 changed files with 4 additions and 3255 deletions
21
AAA
21
AAA
|
|
@ -1,21 +0,0 @@
|
|||
/*
|
||||
Blink
|
||||
Turns on an LED on for one second, then off for one second, repeatedly.
|
||||
|
||||
This example code code code codecodecodecodecodecodecodecodecodecodecodecode is in the public domain.
|
||||
*/
|
||||
int LEDPIN = 13;
|
||||
|
||||
void setup() {
|
||||
//Serial.begin(9600);
|
||||
// initialize the digital pin as an output.
|
||||
// Pin 13 has an LED connected on most Arduino boards:
|
||||
pinMode(LEDPIN, OUTPUT);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
digitalWrite(LEDPIN, HIGH); // set the LED on
|
||||
delay(1000); // wait for a second
|
||||
digitalWrite(LEDPIN, LOW); // set the LED off
|
||||
delay(1000); // wait for a second
|
||||
}
|
||||
|
|
@ -1,66 +0,0 @@
|
|||
void alle(int CMD)
|
||||
{
|
||||
for(int i=0;i<8;i++) {
|
||||
digitalWrite(i, CMD);
|
||||
}
|
||||
}
|
||||
|
||||
void setup()
|
||||
{
|
||||
pinMode(0, OUTPUT);
|
||||
pinMode(1, OUTPUT);
|
||||
pinMode(2, OUTPUT);
|
||||
pinMode(3, OUTPUT);
|
||||
pinMode(4, OUTPUT);
|
||||
pinMode(5, OUTPUT);
|
||||
pinMode(6, OUTPUT);
|
||||
pinMode(7, OUTPUT);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
alle(HIGH);
|
||||
delay(500);
|
||||
alle(LOW);
|
||||
delay(500);
|
||||
/*
|
||||
digitalWrite(0, HIGH);
|
||||
delay(500);
|
||||
digitalWrite(0, LOW);
|
||||
delay(500);
|
||||
|
||||
digitalWrite(1, HIGH);
|
||||
delay(500);
|
||||
digitalWrite(1, LOW);
|
||||
delay(500);
|
||||
|
||||
digitalWrite(2, HIGH);
|
||||
delay(500);
|
||||
digitalWrite(2, LOW);
|
||||
delay(500);
|
||||
|
||||
digitalWrite(3, HIGH);
|
||||
delay(500);
|
||||
digitalWrite(3, LOW);
|
||||
delay(500);
|
||||
|
||||
digitalWrite(4, HIGH);
|
||||
delay(500);
|
||||
digitalWrite(4, LOW);
|
||||
delay(500);
|
||||
|
||||
digitalWrite(5, HIGH);
|
||||
delay(500);
|
||||
digitalWrite(5, LOW);
|
||||
delay(500);
|
||||
|
||||
digitalWrite(6, HIGH);
|
||||
delay(500);
|
||||
digitalWrite(6, LOW);
|
||||
delay(500);
|
||||
|
||||
digitalWrite(7, HIGH);
|
||||
delay(500);
|
||||
digitalWrite(7, LOW);
|
||||
delay(500); */
|
||||
}
|
||||
|
|
@ -1,29 +1,10 @@
|
|||
/*
|
||||
Blink
|
||||
Turns on an LED on for one second, then off for one second, repeatedly.
|
||||
|
||||
Most Arduinos have an on-board LED you can control. On the Uno and
|
||||
Leonardo, it is attached to digital pin 13. If you're unsure what
|
||||
pin the on-board LED is connected to on your Arduino model, check
|
||||
the documentation at http://www.arduino.cc
|
||||
|
||||
This example code is in the public domain.
|
||||
|
||||
modified 8 May 2014
|
||||
by Scott Fitzgerald
|
||||
*/
|
||||
|
||||
|
||||
// the setup function runs once when you press reset or power the board
|
||||
void setup() {
|
||||
// initialize digital pin 13 as an output.
|
||||
pinMode(13, OUTPUT);
|
||||
}
|
||||
|
||||
// the loop function runs over and over again forever
|
||||
void loop() {
|
||||
digitalWrite(13, HIGH); // turn the LED on (HIGH is the voltage level)
|
||||
delay(1000); // wait for a second
|
||||
digitalWrite(13, LOW); // turn the LED off by making the voltage LOW
|
||||
delay(1000); // wait for a second
|
||||
digitalWrite(13, HIGH);
|
||||
delay(1000);
|
||||
digitalWrite(13, LOW);
|
||||
delay(1000);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,30 +0,0 @@
|
|||
/*
|
||||
Blink
|
||||
Turns on an LED on for one second, then off for one second, repeatedly.
|
||||
|
||||
This example code is in the public domain.
|
||||
*/
|
||||
|
||||
void setup() {
|
||||
Serial.begin(9600);
|
||||
// initialize the digital pin as an output.
|
||||
// Pin 13 has an LED connected on most Arduino boards:
|
||||
pinMode(9, OUTPUT);
|
||||
pinMode(10, OUTPUT);
|
||||
pinMode(11, OUTPUT);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
digitalWrite(9, HIGH); // set the LED on
|
||||
delay(1000); // wait for a second
|
||||
digitalWrite(10, HIGH); // set the LED on
|
||||
delay(1000); // wait for a second
|
||||
digitalWrite(11, HIGH); // set the LED on
|
||||
delay(1000); // wait for a second
|
||||
digitalWrite(9, LOW); // set the LED on
|
||||
delay(1000); // wait for a second
|
||||
digitalWrite(10, LOW); // set the LED on
|
||||
delay(1000); // wait for a second
|
||||
digitalWrite(11, LOW); // set the LED off
|
||||
delay(1000); // wait for a second
|
||||
}
|
||||
14
Blink_GNO
14
Blink_GNO
|
|
@ -1,14 +0,0 @@
|
|||
void setup()
|
||||
{
|
||||
Serial.begin(9600); // USB is always 12 Mbit/sec
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
digitalWrite(13, HIGH);
|
||||
Serial.println("Hello World...");
|
||||
delay(1000);
|
||||
digitalWrite(13, LOW);
|
||||
Serial.println("Hello World...");
|
||||
delay(1000);
|
||||
}
|
||||
|
|
@ -1,19 +0,0 @@
|
|||
/*
|
||||
Blink
|
||||
Turns on an LED on for one second, then off for one second, repeatedly.
|
||||
|
||||
This example code is in the public domain.
|
||||
*/
|
||||
|
||||
void setup() {
|
||||
// initialize the digital pin as an output.
|
||||
// Pin 13 has an LED connected on most Arduino boards:
|
||||
pinMode(13, OUTPUT);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
digitalWrite(13, HIGH); // set the LED on
|
||||
//delay(20); // wait for a second
|
||||
//digitalWrite(13, LOW); // set the LED off
|
||||
//delay(20); // wait for a second
|
||||
}
|
||||
|
|
@ -1,327 +0,0 @@
|
|||
|
||||
#include <LCD4Bit.h>
|
||||
#include <avr/io.h>
|
||||
|
||||
//create object to control an LCD.
|
||||
//number of lines in display=2
|
||||
LCD4Bit lcd = LCD4Bit(2);
|
||||
|
||||
/**
|
||||
* Where is the DCF receiver connected?
|
||||
*/
|
||||
#define DCF77PIN 6
|
||||
/**
|
||||
* Where is the LED connected?
|
||||
*/
|
||||
#define BLINKPIN 13
|
||||
/**
|
||||
* Turn debugging on or off
|
||||
*/
|
||||
//#define DCF_DEBUG 1
|
||||
/**
|
||||
* Number of milliseconds to elapse before we assume a "1",
|
||||
* if we receive a falling flank before - its a 0.
|
||||
*/
|
||||
#define DCF_split_millis 140
|
||||
/**
|
||||
* There is no signal in second 59 - detect the beginning of
|
||||
* a new minute.
|
||||
*/
|
||||
#define DCF_sync_millis 1200
|
||||
/**
|
||||
* Definitions for the timer interrupt 2 handler:
|
||||
* The Arduino runs at 16 Mhz, we use a prescaler of 64 -> We need to
|
||||
* initialize the counter with 6. This way, we have 1000 interrupts per second.
|
||||
* We use tick_counter to count the interrupts.
|
||||
*/
|
||||
#define INIT_TIMER_COUNT 6
|
||||
#define RESET_TIMER2 TCNT2 = INIT_TIMER_COUNT
|
||||
int tick_counter = 0;
|
||||
/**
|
||||
* DCF time format struct
|
||||
*/
|
||||
struct DCF77Buffer {
|
||||
unsigned long long prefix :21;
|
||||
unsigned long long Min :7; // minutes
|
||||
unsigned long long P1 :1; // parity minutes
|
||||
unsigned long long Hour :6; // hours
|
||||
unsigned long long P2 :1; // parity hours
|
||||
unsigned long long Day :6; // day
|
||||
unsigned long long Weekday :3; // day of week
|
||||
unsigned long long Month :5; // month
|
||||
unsigned long long Year :8; // year (5 -> 2005)
|
||||
unsigned long long P3 :1; // parity
|
||||
};
|
||||
struct {
|
||||
unsigned char parity_flag :1;
|
||||
unsigned char parity_min :1;
|
||||
unsigned char parity_hour :1;
|
||||
unsigned char parity_date :1;
|
||||
} flags;
|
||||
/**
|
||||
* Clock variables
|
||||
*/
|
||||
volatile unsigned char DCFSignalState = 0;
|
||||
unsigned char previousSignalState;
|
||||
int previousFlankTime;
|
||||
int bufferPosition;
|
||||
unsigned long long dcf_rx_buffer;
|
||||
/**
|
||||
* time vars: the time is stored here!
|
||||
*/
|
||||
volatile unsigned char ss;
|
||||
volatile unsigned char mm;
|
||||
volatile unsigned char hh;
|
||||
volatile unsigned char day;
|
||||
volatile unsigned char mon;
|
||||
volatile unsigned int year;
|
||||
|
||||
|
||||
/**
|
||||
* used in main loop: detect a new second...
|
||||
*/
|
||||
unsigned char previousSecond;
|
||||
|
||||
/**
|
||||
* Initialize the DCF77 routines: initialize the variables,
|
||||
* configure the interrupt behaviour.
|
||||
*/
|
||||
void DCF77Init() {
|
||||
previousSignalState=0;
|
||||
previousFlankTime=0;
|
||||
bufferPosition=0;
|
||||
dcf_rx_buffer=0;
|
||||
ss=mm=hh=day=mon=year=0;
|
||||
#ifdef DCF_DEBUG
|
||||
Serial.println("Initializing DCF77 routines");
|
||||
Serial.print("Using DCF77 pin #");
|
||||
Serial.println(DCF77PIN);
|
||||
pinMode(BLINKPIN, OUTPUT);
|
||||
pinMode(DCF77PIN, INPUT);
|
||||
#endif
|
||||
pinMode(DCF77PIN, INPUT);
|
||||
#ifdef DCF_DEBUG
|
||||
Serial.println("Initializing timerinterrupt");
|
||||
#endif
|
||||
//Timer2 Settings: Timer Prescaler /64,
|
||||
TCCR2 |= (1<<CS22); // turn on CS22 bit
|
||||
TCCR2 &= ~((1<<CS21) | (1<<CS20)); // turn off CS21 and CS20 bits
|
||||
// Use normal mode
|
||||
TCCR2 &= ~((1<<WGM21) | (1<<WGM20)); // turn off WGM21 and WGM20 bits
|
||||
// Use internal clock - external clock not used in Arduino
|
||||
ASSR |= (0<<AS2);
|
||||
TIMSK |= (1<<TOIE2) | (0<<OCIE2); //Timer2 Overflow Interrupt Enable
|
||||
RESET_TIMER2;
|
||||
#ifdef DCF_DEBUG
|
||||
Serial.println("Initializing DCF77 signal listener interrupt");
|
||||
#endif
|
||||
attachInterrupt(0, int0handler, CHANGE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Append a signal to the dcf_rx_buffer. Argument can be 1 or 0. An internal
|
||||
* counter shifts the writing position within the buffer. If position > 59,
|
||||
* a new minute begins -> time to call finalizeBuffer().
|
||||
*/
|
||||
void appendSignal(unsigned char signal) {
|
||||
#ifdef DCF_DEBUG
|
||||
Serial.print(", appending value ");
|
||||
Serial.print(signal, DEC);
|
||||
Serial.print(" at position ");
|
||||
Serial.println(bufferPosition);
|
||||
#endif
|
||||
dcf_rx_buffer = dcf_rx_buffer | ((unsigned long long) signal << bufferPosition);
|
||||
// Update the parity bits. First: Reset when minute, hour or date starts.
|
||||
if (bufferPosition == 21 || bufferPosition == 29 || bufferPosition == 36) {
|
||||
flags.parity_flag = 0;
|
||||
}
|
||||
// save the parity when the corresponding segment ends
|
||||
if (bufferPosition == 28) {flags.parity_min = flags.parity_flag;};
|
||||
if (bufferPosition == 35) {flags.parity_hour = flags.parity_flag;};
|
||||
if (bufferPosition == 58) {flags.parity_date = flags.parity_flag;};
|
||||
// When we received a 1, toggle the parity flag
|
||||
if (signal == 1) {
|
||||
flags.parity_flag = flags.parity_flag ^ 1;
|
||||
}
|
||||
bufferPosition++;
|
||||
if (bufferPosition > 59) {
|
||||
finalizeBuffer();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Evaluates the information stored in the buffer. This is where the DCF77
|
||||
* signal is decoded and the internal clock is updated.
|
||||
*/
|
||||
void finalizeBuffer(void) {
|
||||
if (bufferPosition == 59) {
|
||||
#ifdef DCF_DEBUG
|
||||
Serial.println("Finalizing Buffer");
|
||||
#endif
|
||||
struct DCF77Buffer *rx_buffer;
|
||||
rx_buffer = (struct DCF77Buffer *)(unsigned long long)&dcf_rx_buffer;
|
||||
if (flags.parity_min == rx_buffer->P1 &&
|
||||
flags.parity_hour == rx_buffer->P2 &&
|
||||
flags.parity_date == rx_buffer->P3)
|
||||
{
|
||||
#ifdef DCF_DEBUG
|
||||
Serial.println("Parity check OK - updating time.");
|
||||
#endif
|
||||
//convert the received bits from BCD
|
||||
mm = rx_buffer->Min-((rx_buffer->Min/16)*6);
|
||||
hh = rx_buffer->Hour-((rx_buffer->Hour/16)*6);
|
||||
day= rx_buffer->Day-((rx_buffer->Day/16)*6);
|
||||
mon= rx_buffer->Month-((rx_buffer->Month/16)*6);
|
||||
year= 2000 + rx_buffer->Year-((rx_buffer->Year/16)*6);
|
||||
}
|
||||
#ifdef DCF_DEBUG
|
||||
else {
|
||||
Serial.println("Parity check NOK - running on internal clock.");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
// reset stuff
|
||||
ss = 0;
|
||||
bufferPosition = 0;
|
||||
dcf_rx_buffer=0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Dump the time to the serial line.
|
||||
*/
|
||||
void serialDumpTime(void){
|
||||
Serial.print("Time: ");
|
||||
Serial.print(hh, DEC);
|
||||
Serial.print(":");
|
||||
Serial.print(mm, DEC);
|
||||
Serial.print(":");
|
||||
Serial.print(ss, DEC);
|
||||
Serial.print(" Date: ");
|
||||
Serial.print(day, DEC);
|
||||
Serial.print(".");
|
||||
Serial.print(mon, DEC);
|
||||
Serial.print(".");
|
||||
Serial.println(year, DEC);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Evaluates the signal as it is received. Decides whether we received
|
||||
* a "1" or a "0" based on the
|
||||
*/
|
||||
void scanSignal(void){
|
||||
if (DCFSignalState == 1) {
|
||||
int thisFlankTime=millis();
|
||||
if (thisFlankTime - previousFlankTime > DCF_sync_millis) {
|
||||
#ifdef DCF_DEBUG
|
||||
Serial.println("####");
|
||||
Serial.println("#### Begin of new Minute!!!");
|
||||
Serial.println("####");
|
||||
#endif
|
||||
finalizeBuffer();
|
||||
}
|
||||
previousFlankTime=thisFlankTime;
|
||||
#ifdef DCF_DEBUG
|
||||
Serial.print(previousFlankTime);
|
||||
Serial.print(": DCF77 Signal detected, ");
|
||||
#endif
|
||||
}
|
||||
else {
|
||||
/* or a falling flank */
|
||||
int difference=millis() - previousFlankTime;
|
||||
#ifdef DCF_DEBUG
|
||||
Serial.print("duration: ");
|
||||
Serial.print(difference);
|
||||
#endif
|
||||
if (difference < DCF_split_millis) {
|
||||
appendSignal(0);
|
||||
}
|
||||
else {
|
||||
appendSignal(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The interrupt routine for counting seconds - increment hh:mm:ss.
|
||||
*/
|
||||
ISR(TIMER2_OVF_vect) {
|
||||
RESET_TIMER2;
|
||||
tick_counter += 1;
|
||||
if (tick_counter == 1000) {
|
||||
ss++;
|
||||
if (ss==60) {
|
||||
ss=0;
|
||||
mm++;
|
||||
if (mm==60) {
|
||||
mm=0;
|
||||
hh++;
|
||||
if (hh==24)
|
||||
hh=0;
|
||||
}
|
||||
}
|
||||
tick_counter = 0;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Interrupthandler for INT0 - called when the signal on Pin 2 changes.
|
||||
*/
|
||||
void int0handler() {
|
||||
// check the value again - since it takes some time to
|
||||
// activate the interrupt routine, we get a clear signal.
|
||||
DCFSignalState = digitalRead(DCF77PIN);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Standard Arduino methods below.
|
||||
*/
|
||||
|
||||
void setup(void) {
|
||||
|
||||
//pinMode(13, OUTPUT); //we'll use the debug LED to output a heartbeat
|
||||
//lcd.init();
|
||||
|
||||
// We need to start serial here again,
|
||||
// for Arduino 007 (new serial code)
|
||||
Serial.begin(9600);
|
||||
DCF77Init();
|
||||
}
|
||||
|
||||
void loop(void) {
|
||||
if (ss != previousSecond) {
|
||||
serialDumpTime();
|
||||
previousSecond = ss;
|
||||
}
|
||||
if (DCFSignalState != previousSignalState) {
|
||||
scanSignal();
|
||||
if (DCFSignalState) {
|
||||
digitalWrite(BLINKPIN, HIGH);
|
||||
} else {
|
||||
digitalWrite(BLINKPIN, LOW);
|
||||
}
|
||||
previousSignalState = DCFSignalState;
|
||||
}
|
||||
//delay(20);
|
||||
}
|
||||
|
||||
void loop22() {
|
||||
|
||||
lcd.clear(); // Clear display
|
||||
|
||||
lcd.printIn("hallo welt!"); // Dislay text on first line
|
||||
lcd.leftScroll(32, 200);
|
||||
//lcd.cursorTo(2,0); // Move cursor to second line, position 0
|
||||
|
||||
//lcd.printIn("fuck off!"); // Display text on second line
|
||||
/*
|
||||
while(1) // Endless loop flashing the LED
|
||||
{
|
||||
digitalWrite(13, HIGH);
|
||||
delay(1000);
|
||||
digitalWrite(13, LOW);
|
||||
delay(1000);
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
|
@ -1,143 +0,0 @@
|
|||
|
||||
//#include <LiquidCrystal.h>
|
||||
|
||||
//LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
|
||||
|
||||
#include <SoftwareSerial.h>
|
||||
|
||||
|
||||
#define rxPin 0
|
||||
#define txPin 1
|
||||
#define ledPin 13
|
||||
|
||||
#define rstPin 6
|
||||
#define clkPin 7
|
||||
#define dqPin 8
|
||||
|
||||
#define tempPin 0
|
||||
|
||||
// set up a new serial port
|
||||
SoftwareSerial mySerial = SoftwareSerial(rxPin, txPin);
|
||||
byte pinState = 0;
|
||||
|
||||
void setup() {
|
||||
// define pin modes for tx, rx, led pins:
|
||||
pinMode(rxPin, INPUT);
|
||||
pinMode(txPin, OUTPUT);
|
||||
|
||||
pinMode(ledPin, OUTPUT);
|
||||
pinMode(rstPin, OUTPUT);
|
||||
pinMode(clkPin, OUTPUT);
|
||||
pinMode(dqPin, OUTPUT);
|
||||
|
||||
// set the data rate for the SoftwareSerial port
|
||||
mySerial.begin(9600);
|
||||
|
||||
//lcd.begin(16, 2);
|
||||
//lcd.print("Temperature:");
|
||||
}
|
||||
|
||||
|
||||
void loop() {
|
||||
float temp;
|
||||
|
||||
rst_low();
|
||||
|
||||
clk_high();
|
||||
rst_high(); //all data transfer are initiated by driving RST high
|
||||
write_command(0x0c); // write config command
|
||||
write_command(0x02); // cpu mode
|
||||
rst_low();
|
||||
delay(200); //wait until the configuration register is written
|
||||
|
||||
clk_high();
|
||||
rst_high();
|
||||
write_command(0x51); //start conversion
|
||||
rst_low();
|
||||
delay(200);
|
||||
|
||||
clk_high();
|
||||
rst_high();
|
||||
write_command(0xAA);
|
||||
int raw_data = read_raw_data();
|
||||
rst_low();
|
||||
|
||||
mySerial.print("temperature:");
|
||||
mySerial.print(raw_data/20);
|
||||
mySerial.println(" C");
|
||||
|
||||
/*
|
||||
temp = analogRead(tempPin);
|
||||
//temp = temp * 0.48828125;
|
||||
temp = (5.0 * temp * 100.0)/1024.0;
|
||||
lcd.setCursor(0, 1);
|
||||
lcd.print(temp);
|
||||
//lcd.print(" ");
|
||||
//lcd.print("wsew");
|
||||
|
||||
|
||||
delay(1000);
|
||||
*/
|
||||
delay(1000);
|
||||
|
||||
}
|
||||
|
||||
void write_command(int command)
|
||||
/* sends 8 bit command on DQ output, least sig bit first */
|
||||
{
|
||||
int n, bit;
|
||||
|
||||
for(n=0;n<8;n++)
|
||||
{
|
||||
bit = ((command >> n) & (0x01));
|
||||
out_bit(bit);
|
||||
}
|
||||
}
|
||||
|
||||
int read_raw_data(void)
|
||||
{
|
||||
int bit,n;
|
||||
int raw_data=0;
|
||||
|
||||
pinMode(dqPin,INPUT);
|
||||
|
||||
/* jam the dq lead high to use as input */
|
||||
for(n=0;n<9;n++)
|
||||
{
|
||||
clk_low();
|
||||
bit=(digitalRead(dqPin));
|
||||
clk_high();
|
||||
raw_data = raw_data | (bit << n);
|
||||
}
|
||||
pinMode(dqPin, OUTPUT);
|
||||
return(raw_data);
|
||||
}
|
||||
|
||||
void out_bit(int bit)
|
||||
{
|
||||
digitalWrite(dqPin, bit); /* set up the data */
|
||||
clk_low(); /* and then provide a clock pulse */
|
||||
clk_high();
|
||||
}
|
||||
|
||||
void clk_high(void)
|
||||
{
|
||||
digitalWrite(clkPin,HIGH);
|
||||
}
|
||||
|
||||
void clk_low(void)
|
||||
{
|
||||
digitalWrite(clkPin,LOW);
|
||||
}
|
||||
|
||||
void rst_high(void)
|
||||
{
|
||||
digitalWrite(rstPin,HIGH);
|
||||
}
|
||||
|
||||
void rst_low(void)
|
||||
{
|
||||
digitalWrite(rstPin,LOW);
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -1,36 +0,0 @@
|
|||
/*
|
||||
* Dimmer
|
||||
* by David A. Mellis
|
||||
*
|
||||
* Demonstrates the sending data from the computer to the Arduino board,
|
||||
* in this case to control the brightness of an LED. The data is sent
|
||||
* in individual bytes, each of which ranges from 0 to 255. Arduino
|
||||
* reads these bytes and uses them to set the brightness of the LED.
|
||||
*
|
||||
* http://www.arduino.cc/en/Tutorial/Dimmer
|
||||
*/
|
||||
|
||||
int ledPin = 13;
|
||||
|
||||
void setup()
|
||||
{
|
||||
// begin the serial communication
|
||||
Serial.begin(9600);
|
||||
pinMode(ledPin, OUTPUT);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
byte val;
|
||||
|
||||
// check if data has been sent from the computer
|
||||
if (Serial.available()) {
|
||||
// read the most recent byte (which will be from 0 to 255)
|
||||
val = Serial.read();
|
||||
// set the brightness of the LED
|
||||
analogWrite(ledPin, val);
|
||||
//Serial.write(255);
|
||||
Serial.write(val/2);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,61 +0,0 @@
|
|||
/*
|
||||
LiquidCrystal Library - display() and noDisplay()
|
||||
|
||||
Demonstrates the use a 16x2 LCD display. The LiquidCrystal
|
||||
library works with all LCD displays that are compatible with the
|
||||
Hitachi HD44780 driver. There are many of them out there, and you
|
||||
can usually tell them by the 16-pin interface.
|
||||
|
||||
This sketch prints "Hello World!" to the LCD and uses the
|
||||
display() and noDisplay() functions to turn on and off
|
||||
the display.
|
||||
|
||||
The circuit:
|
||||
* LCD RS pin to digital pin 12
|
||||
* LCD Enable pin to digital pin 11
|
||||
* LCD D4 pin to digital pin 5
|
||||
* LCD D5 pin to digital pin 4
|
||||
* LCD D6 pin to digital pin 3
|
||||
* LCD D7 pin to digital pin 2
|
||||
* LCD R/W pin to ground
|
||||
* 10K resistor:
|
||||
* ends to +5V and ground
|
||||
* wiper to LCD VO pin (pin 3)
|
||||
|
||||
Library originally added 18 Apr 2008
|
||||
by David A. Mellis
|
||||
library modified 5 Jul 2009
|
||||
by Limor Fried (http://www.ladyada.net)
|
||||
example added 9 Jul 2009
|
||||
by Tom Igoe
|
||||
modified 22 Nov 2010
|
||||
by Tom Igoe
|
||||
|
||||
This example code is in the public domain.
|
||||
|
||||
http://www.arduino.cc/en/Tutorial/LiquidCrystal
|
||||
*/
|
||||
|
||||
// include the library code:
|
||||
#include <LiquidCrystal.h>
|
||||
|
||||
// initialize the library with the numbers of the interface pins
|
||||
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
|
||||
|
||||
void setup() {
|
||||
// set up the LCD's number of columns and rows:
|
||||
lcd.begin(16, 2);
|
||||
// Print a message to the LCD.
|
||||
lcd.print("hello, world!");
|
||||
delay(5000);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// Turn off the display:
|
||||
lcd.noDisplay();
|
||||
delay(500);
|
||||
// Turn on the display:
|
||||
lcd.display();
|
||||
delay(500);
|
||||
}
|
||||
|
||||
|
|
@ -1,79 +0,0 @@
|
|||
|
||||
#include <LiquidCrystal.h>
|
||||
|
||||
// Connections:
|
||||
// rs (LCD pin 4) to Arduino pin 12
|
||||
// rw (LCD pin 5) to Arduino pin 11
|
||||
// enable (LCD pin 6) to Arduino pin 10
|
||||
// LCD pin 15 to Arduino pin 13
|
||||
// LCD pins d4, d5, d6, d7 to Arduino pins 5, 4, 3, 2
|
||||
LiquidCrystal lcd(12, 11, 10, 5, 4, 3, 2);
|
||||
|
||||
#define OUTPIN 7
|
||||
#define INPIN 8
|
||||
|
||||
void setup()
|
||||
{
|
||||
|
||||
pinMode(OUTPIN, OUTPUT);
|
||||
digitalWrite(OUTPIN, LOW);
|
||||
pinMode(INPIN, INPUT);
|
||||
pinMode(13, OUTPUT);
|
||||
digitalWrite(13, LOW); // turn backlight on. Replace 'HIGH' with 'LOW' to turn it off.
|
||||
|
||||
|
||||
|
||||
|
||||
lcd.begin(16,2); // columns, rows. use 16,2 for a 16x2 LCD, etc.
|
||||
lcd.clear(); // start with a blank screen
|
||||
lcd.setCursor(0,0); // set cursor to column 0, row 0 (the first row)
|
||||
lcd.print("Hej Katrin..."); // change this text to whatever you like. keep it clean.
|
||||
lcd.setCursor(0,1); // set cursor to column 0, row 1
|
||||
lcd.print("Jeg elsker dig!");
|
||||
|
||||
// if you have a 4 row LCD, uncomment these lines to write to the bottom rows
|
||||
// and change the lcd.begin() statement above.
|
||||
//lcd.setCursor(0,2); // set cursor to column 0, row 2
|
||||
//lcd.print("Row 3");
|
||||
//lcd.setCursor(0,3); // set cursor to column 0, row 3
|
||||
//lcd.print("Row 4");
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
/*
|
||||
boolean val = digitalRead(INPIN);
|
||||
|
||||
if(val == LOW) {
|
||||
digitalWrite(OUTPIN, LOW);
|
||||
digitalWrite(13, LOW);
|
||||
|
||||
}
|
||||
|
||||
if(val == HIGH) {
|
||||
for(int i = 15; i >= 0; i--) {
|
||||
lcd.clear();
|
||||
lcd.setCursor(i,1);
|
||||
lcd.print("<");
|
||||
delay(200);
|
||||
}
|
||||
for(int i = 0; i <= 15; i++) {
|
||||
lcd.clear();
|
||||
lcd.setCursor(i,0);
|
||||
lcd.print(">");
|
||||
delay(200);
|
||||
if(i == 15) {
|
||||
lcd.clear();
|
||||
}
|
||||
|
||||
}
|
||||
digitalWrite(OUTPIN, HIGH);
|
||||
digitalWrite(13, HIGH);
|
||||
// delay(200);
|
||||
}
|
||||
*/
|
||||
//
|
||||
///}
|
||||
delay(333);
|
||||
|
||||
}
|
||||
|
|
@ -1,35 +0,0 @@
|
|||
/*
|
||||
Fade
|
||||
|
||||
This example shows how to fade an LED on pin 9
|
||||
using the analogWrite() function.
|
||||
|
||||
This example code is in the public domain.
|
||||
*/
|
||||
|
||||
int led = 11; // the pin that the LED is attached to
|
||||
int brightness = 0; // how bright the LED is
|
||||
int fadeAmount = 5; // how many points to fade the LED by
|
||||
|
||||
// the setup routine runs once when you press reset:
|
||||
void setup() {
|
||||
// declare pin 9 to be an output:
|
||||
pinMode(led, OUTPUT);
|
||||
}
|
||||
|
||||
// the loop routine runs over and over again forever:
|
||||
void loop() {
|
||||
// set the brightness of pin 9:
|
||||
analogWrite(led, brightness);
|
||||
|
||||
// change the brightness for next time through the loop:
|
||||
brightness = brightness + fadeAmount;
|
||||
|
||||
// reverse the direction of the fading at the ends of the fade:
|
||||
if (brightness == 0 || brightness == 255) {
|
||||
fadeAmount = -fadeAmount ;
|
||||
}
|
||||
// wait for 30 milliseconds to see the dimming effect
|
||||
delay(30);
|
||||
}
|
||||
|
||||
|
|
@ -1,43 +0,0 @@
|
|||
/*
|
||||
Fade
|
||||
|
||||
This example shows how to fade an LED on pin 9
|
||||
using the analogWrite() function.
|
||||
|
||||
This example code is in the public domain.
|
||||
|
||||
*/
|
||||
int brightness1 = 0; // how bright the LED is
|
||||
int brightness2 = 85; // how bright the LED is
|
||||
int brightness3 = 170; // how bright the LED is
|
||||
int fadeAmount1 = 5; // how many points to fade the LED by
|
||||
int fadeAmount2 = 5; // how many points to fade the LED by
|
||||
int fadeAmount3 = 5; // how many points to fade the LED by
|
||||
|
||||
void setup() {
|
||||
pinMode(9, OUTPUT);
|
||||
pinMode(10, OUTPUT);
|
||||
pinMode(11, OUTPUT);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
analogWrite(9, brightness1);
|
||||
analogWrite(10, brightness2);
|
||||
analogWrite(11, brightness3);
|
||||
|
||||
brightness1 = brightness1 + fadeAmount1;
|
||||
brightness2 = brightness2 + fadeAmount2;
|
||||
brightness3 = brightness3 + fadeAmount3;
|
||||
|
||||
if (brightness1 == 0 || brightness1 == 255) {
|
||||
fadeAmount1 = -fadeAmount1 ;
|
||||
}
|
||||
if (brightness2 == 0 || brightness2 == 255) {
|
||||
fadeAmount2 = -fadeAmount2 ;
|
||||
}
|
||||
if (brightness3 == 0 || brightness3 == 255) {
|
||||
fadeAmount3 = -fadeAmount3 ;
|
||||
}
|
||||
|
||||
delay(250);
|
||||
}
|
||||
|
|
@ -1,33 +0,0 @@
|
|||
/*
|
||||
Fade
|
||||
|
||||
This example shows how to fade an LED on pin 9
|
||||
using the analogWrite() function.
|
||||
|
||||
This example code is in the public domain.
|
||||
|
||||
*/
|
||||
int brightness = 0; // how bright the LED is
|
||||
int fadeAmount = 5; // how many points to fade the LED by
|
||||
|
||||
void setup() {
|
||||
// declare pin 9 to be an output:
|
||||
pinMode(1, OUTPUT);
|
||||
pinMode(11, OUTPUT);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// set the brightness of pin 9:
|
||||
analogWrite(1, brightness);
|
||||
analogWrite(11, brightness);
|
||||
|
||||
// change the brightness for next time through the loop:
|
||||
brightness = brightness + fadeAmount;
|
||||
|
||||
// reverse the direction of the fading at the ends of the fade:
|
||||
if (brightness == 0 || brightness == 255) {
|
||||
fadeAmount = -fadeAmount ;
|
||||
}
|
||||
// wait for 30 milliseconds to see the dimming effect
|
||||
delay(30);
|
||||
}
|
||||
|
|
@ -1,51 +0,0 @@
|
|||
|
||||
|
||||
#include <LCD4Bit.h>
|
||||
|
||||
//create object to control an LCD.
|
||||
//number of lines in display=2
|
||||
LCD4Bit lcd = LCD4Bit(2);
|
||||
|
||||
|
||||
|
||||
|
||||
void setup(void) {
|
||||
pinMode(13, OUTPUT); //we'll use the debug LED to output a heartbeat
|
||||
lcd.init();
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
||||
lcd.clear(); // Clear display
|
||||
|
||||
//lcd.printIn("fuck the world guys... ?"); // Dislay text on first line
|
||||
//lcd.leftScroll(32, 600);
|
||||
// lcd.cursorTo(2,0); // Move cursor to second line, position 0
|
||||
|
||||
//lcd.printIn("<<<<fuck off>>>>"); // Display text on second line
|
||||
|
||||
|
||||
lcd.printIn("Hey guys...");
|
||||
lcd.cursorTo(2,0);
|
||||
delay(5000);
|
||||
lcd.printIn("what's up?");
|
||||
delay(5000);
|
||||
lcd.cursorTo(1,0);
|
||||
lcd.printIn("Hehehehehhe....");
|
||||
lcd.cursorTo(2,0);
|
||||
lcd.printIn(".................");
|
||||
delay(10000);
|
||||
//lcd.printIn("");
|
||||
//lcd.printIn("");
|
||||
|
||||
delay(5000);
|
||||
/*
|
||||
while(1) // Endless loop flashing the LED
|
||||
{
|
||||
digitalWrite(13, HIGH);
|
||||
delay(1000);
|
||||
digitalWrite(13, LOW);
|
||||
delay(1000);
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
|
@ -1,47 +0,0 @@
|
|||
//example use of LCD4Bit library
|
||||
|
||||
#include <LCD4Bit.h>
|
||||
//create object to control an LCD.
|
||||
//number of lines in display=1
|
||||
LCD4Bit lcd = LCD4Bit(2);
|
||||
|
||||
//some messages to display on the LCD
|
||||
char msgs[6][15] = {"apple", "banana", "pineapple", "mango", "watermelon", "pear"};
|
||||
int NUM_MSGS = 6;
|
||||
|
||||
void setup() {
|
||||
pinMode(13, OUTPUT); //we'll use the debug LED to output a heartbeat
|
||||
|
||||
lcd.init();
|
||||
//optionally, now set up our application-specific display settings, overriding whatever the lcd did in lcd.init()
|
||||
//lcd.commandWrite(0x0F);//cursor on, display on, blink on. (nasty!)
|
||||
}
|
||||
|
||||
void loop() {
|
||||
digitalWrite(13, HIGH); //light the debug LED
|
||||
|
||||
//pick a random message from the array
|
||||
int pick = random(NUM_MSGS);
|
||||
char* msg = msgs[pick];
|
||||
|
||||
lcd.clear();
|
||||
lcd.printIn(msg);
|
||||
delay(1000);
|
||||
digitalWrite(13, LOW);
|
||||
|
||||
//print some dots individually
|
||||
for (int i=0; i<3; i++){
|
||||
lcd.print('.');
|
||||
delay(100);
|
||||
}
|
||||
//print something on the display's second line.
|
||||
//uncomment this if your display HAS two lines!
|
||||
/*
|
||||
lcd.cursorTo(2, 0); //line=2, x=0.
|
||||
lcd.printIn("Score: 6/7");
|
||||
delay(1000);
|
||||
*/
|
||||
|
||||
//scroll entire display 20 chars to left, delaying 50ms each inc
|
||||
lcd.leftScroll(20, 50);
|
||||
}
|
||||
|
|
@ -1,29 +0,0 @@
|
|||
|
||||
|
||||
|
||||
int buttonState = 0;
|
||||
|
||||
void setup() {
|
||||
|
||||
Serial.begin(9600);
|
||||
|
||||
|
||||
pinMode(7, INPUT);
|
||||
pinMode(13, OUTPUT);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
||||
|
||||
|
||||
buttonState = digitalRead(7);
|
||||
|
||||
if (buttonState == HIGH) {
|
||||
digitalWrite(13, HIGH);
|
||||
}
|
||||
else {
|
||||
digitalWrite(13, LOW);
|
||||
}
|
||||
Serial.println(buttonState, DEC);
|
||||
delay(1000); // wait for a second
|
||||
}
|
||||
|
|
@ -1,15 +0,0 @@
|
|||
|
||||
int ledPin = 13; // LED connected to digital pin 13
|
||||
|
||||
void setup() // run once, when the sketch starts
|
||||
{
|
||||
pinMode(ledPin, OUTPUT); // sets the digital pin as output
|
||||
}
|
||||
|
||||
void loop() // run over and over again
|
||||
{
|
||||
digitalWrite(ledPin, HIGH); // sets the LED on
|
||||
delay(1000); // waits for a second
|
||||
digitalWrite(ledPin, LOW); // sets the LED off
|
||||
delay(1000); // waits for a second
|
||||
}
|
||||
|
|
@ -1,32 +0,0 @@
|
|||
|
||||
int pin_led_clock=2;
|
||||
int pin_led_latch=3;
|
||||
int pin_led_data=4;
|
||||
|
||||
void setup() {
|
||||
Serial.begin(9600); //start serial
|
||||
pinMode(pin_led_data, OUTPUT);
|
||||
pinMode(pin_led_latch, OUTPUT);
|
||||
pinMode(pin_led_clock, OUTPUT);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
set_led_states(LOW);
|
||||
delay(500);
|
||||
set_led_states(HIGH);
|
||||
delay(500);
|
||||
}
|
||||
|
||||
void set_led_states(int CMD){
|
||||
for (int n=0; n<8; n++) {
|
||||
digitalWrite(pin_led_data, CMD); // turn the 'current' led on
|
||||
pulse_pin(pin_led_clock); // address the next bit slot
|
||||
}
|
||||
pulse_pin(pin_led_latch); // when the latch goes from low to high, the data that's been stored to the register's memory gets sent to its output pins
|
||||
}
|
||||
|
||||
// Set a pin to low, then high
|
||||
void pulse_pin(int pin_number){
|
||||
digitalWrite(pin_number,LOW);
|
||||
digitalWrite(pin_number,HIGH);
|
||||
}
|
||||
|
|
@ -1,44 +0,0 @@
|
|||
//**************************************************************//
|
||||
// Name : shiftOutCode, Hello World
|
||||
// Author : Carlyn Maw,Tom Igoe, David A. Mellis
|
||||
// Date : 25 Oct, 2006
|
||||
// Modified: 23 Mar 2010
|
||||
// Version : 2.0
|
||||
// Notes : Code for using a 74HC595 Shift Register //
|
||||
// : to count from 0 to 255
|
||||
//****************************************************************
|
||||
|
||||
//Pin connected to ST_CP of 74HC595
|
||||
int latchPin = 8;
|
||||
//Pin connected to SH_CP of 74HC595
|
||||
int clockPin = 12;
|
||||
////Pin connected to DS of 74HC595
|
||||
int dataPin = 11;
|
||||
|
||||
|
||||
|
||||
void setup() {
|
||||
//set pins to output so you can control the shift register
|
||||
pinMode(latchPin, OUTPUT);
|
||||
pinMode(clockPin, OUTPUT);
|
||||
pinMode(dataPin, OUTPUT);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
||||
for (int numberToDisplay = 0; numberToDisplay < 256; numberToDisplay++) {
|
||||
digitalWrite(latchPin, LOW);
|
||||
shiftOut(dataPin, clockPin, MSBFIRST, numberToDisplay);
|
||||
digitalWrite(latchPin, HIGH);
|
||||
delay(300);
|
||||
}
|
||||
|
||||
for (int numberToDisplay = 255; numberToDisplay >= 0; numberToDisplay--) {
|
||||
digitalWrite(latchPin, LOW);
|
||||
shiftOut(dataPin, clockPin, MSBFIRST, numberToDisplay);
|
||||
digitalWrite(latchPin, HIGH);
|
||||
delay(300);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -1,68 +0,0 @@
|
|||
/*
|
||||
Shift Register Example
|
||||
for 74HC595 shift register
|
||||
|
||||
This sketch turns reads serial input and uses it to set the pins
|
||||
of a 74HC595 shift register.
|
||||
|
||||
Hardware:
|
||||
* 74HC595 shift register attached to pins 2, 3, and 4 of the Arduino,
|
||||
as detailed below.
|
||||
* LEDs attached to each of the outputs of the shift register
|
||||
|
||||
Created 22 May 2009
|
||||
Created 23 Mar 2010
|
||||
by Tom Igoe
|
||||
|
||||
*/
|
||||
|
||||
//Pin connected to latch pin (ST_CP) of 74HC595
|
||||
const int latchPin = 8;
|
||||
//Pin connected to clock pin (SH_CP) of 74HC595
|
||||
const int clockPin = 12;
|
||||
////Pin connected to Data in (DS) of 74HC595
|
||||
const int dataPin = 11;
|
||||
|
||||
void setup() {
|
||||
//set pins to output because they are addressed in the main loop
|
||||
pinMode(latchPin, OUTPUT);
|
||||
pinMode(dataPin, OUTPUT);
|
||||
pinMode(clockPin, OUTPUT);
|
||||
Serial.begin(9600);
|
||||
Serial.println("reset");
|
||||
}
|
||||
|
||||
void loop() {
|
||||
if (Serial.available() > 0) {
|
||||
// ASCII '0' through '9' characters are
|
||||
// represented by the values 48 through 57.
|
||||
// so if the user types a number from 0 through 9 in ASCII,
|
||||
// you can subtract 48 to get the actual value:
|
||||
int bitToSet = Serial.read() - 48;
|
||||
|
||||
// write to the shift register with the correct bit set high:
|
||||
registerWrite(bitToSet, HIGH);
|
||||
}
|
||||
}
|
||||
|
||||
// This method sends bits to the shift register:
|
||||
|
||||
void registerWrite(int whichPin, int whichState) {
|
||||
// the bits you want to send
|
||||
byte bitsToSend = 0;
|
||||
|
||||
// turn off the output so the pins don't light up
|
||||
// while you're shifting bits:
|
||||
digitalWrite(latchPin, LOW);
|
||||
|
||||
// turn on the next highest bit in bitsToSend:
|
||||
bitWrite(bitsToSend, whichPin, whichState);
|
||||
|
||||
// shift the bits out:
|
||||
shiftOut(dataPin, clockPin, MSBFIRST, bitsToSend);
|
||||
|
||||
// turn on the output so the LEDs can light up:
|
||||
digitalWrite(latchPin, HIGH);
|
||||
|
||||
}
|
||||
|
||||
113
Temp/Temp.pde
113
Temp/Temp.pde
|
|
@ -1,113 +0,0 @@
|
|||
|
||||
|
||||
#include <Wire.h>
|
||||
|
||||
#define BUTTON1 2
|
||||
#define BUTTON2 3
|
||||
|
||||
// ds1621 has 0x9(b1001) A0 A1 A2
|
||||
#define DS1621_ADDR ((0x9 << 3) | 0x00)
|
||||
|
||||
// start up ds1621
|
||||
void ds1621_init()
|
||||
{
|
||||
|
||||
Serial.print(DS1621_ADDR, HEX);
|
||||
// write 0x2 to config register 0xac
|
||||
Wire.beginTransmission(DS1621_ADDR);
|
||||
Wire.send(0xac);
|
||||
Wire.send(0x02);
|
||||
Wire.endTransmission();
|
||||
delay(20);
|
||||
|
||||
// tell the ds1621 to start measuring temperature
|
||||
Wire.beginTransmission(DS1621_ADDR);
|
||||
Wire.send(0xEE);
|
||||
Wire.endTransmission();
|
||||
}
|
||||
|
||||
// read temperature
|
||||
unsigned int ds161_read_temp()
|
||||
{
|
||||
unsigned int data;
|
||||
|
||||
// tell ds1621 that we want to read register 0xaa (the temperature is in there)
|
||||
Wire.beginTransmission(DS1621_ADDR);
|
||||
Wire.send(0xaa);
|
||||
Wire.endTransmission();
|
||||
|
||||
// start reading the 2 bytes of temp data
|
||||
Wire.beginTransmission(DS1621_ADDR);
|
||||
Wire.requestFrom(DS1621_ADDR, 2);
|
||||
if(Wire.available())
|
||||
data = Wire.receive() << 8;
|
||||
if(Wire.available())
|
||||
data |= Wire.receive();
|
||||
return data;
|
||||
}
|
||||
|
||||
// format and output the temperature read from a ds1621
|
||||
void ds1621_print_temp(int temp)
|
||||
{
|
||||
if(temp & 0x8000)
|
||||
Serial.print("-");
|
||||
else
|
||||
Serial.print("");
|
||||
temp &= 0x7fff;
|
||||
Serial.print(temp >> 8);
|
||||
if(temp & 0xff)
|
||||
Serial.print(",5");
|
||||
else
|
||||
Serial.print(",0");
|
||||
Serial.print("\n");
|
||||
delay(1000);
|
||||
}
|
||||
int a = 0;
|
||||
// this function is called everytime button1 is pressed
|
||||
void button1_isr(void)
|
||||
{
|
||||
// Serial.print("button1\n");
|
||||
a= 1;
|
||||
}
|
||||
|
||||
// this function is called everytime button2 is pressed
|
||||
void button2_isr(void)
|
||||
{
|
||||
//Serial.print("button2\n");
|
||||
a=2;
|
||||
}
|
||||
|
||||
void setup()
|
||||
{
|
||||
|
||||
pinMode(13, OUTPUT); //we'll use the debug LED to output a heartbeat
|
||||
|
||||
// start serial
|
||||
Serial.begin(9600);
|
||||
|
||||
// start i2c
|
||||
Wire.begin();
|
||||
|
||||
// start thermometer
|
||||
ds1621_init();
|
||||
|
||||
// setup button gpio
|
||||
// gpio is input and internal pullup enabled
|
||||
pinMode(BUTTON1, INPUT);
|
||||
pinMode(BUTTON2, INPUT);
|
||||
digitalWrite(BUTTON1, HIGH);
|
||||
digitalWrite(BUTTON2, HIGH);
|
||||
|
||||
// give both buttons an interrupt handler
|
||||
attachInterrupt(0, button1_isr, FALLING);
|
||||
attachInterrupt(1, button2_isr, FALLING);
|
||||
interrupts();
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
|
||||
int temp = ds161_read_temp();
|
||||
ds1621_print_temp(temp);
|
||||
delay(1000);
|
||||
}
|
||||
|
|
@ -1,48 +0,0 @@
|
|||
#include <Wire.h>
|
||||
|
||||
// ds1621 has 0x9(b1001) A0 A1 A2
|
||||
//#define DS1621_ADDR 72
|
||||
#define DS1621_ADDR ((0x9 << 3) | 0x00)
|
||||
|
||||
void setup()
|
||||
{
|
||||
// start serial
|
||||
Serial.begin(9600);
|
||||
|
||||
// write 0x2 to config register 0xac
|
||||
Wire.begin(DS1621_ADDR);
|
||||
Wire.send(0xac);
|
||||
Wire.send(0x02);
|
||||
|
||||
delay(20);
|
||||
|
||||
// tell the ds1621 to start measuring temperature
|
||||
Wire.send(0xee);
|
||||
|
||||
// tell ds1621 that we want to read register
|
||||
// 0xaa (the temperature is in there)
|
||||
Wire.send(0xaa);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
unsigned int data;
|
||||
|
||||
// start reading the 2 bytes of temp data
|
||||
Wire.requestFrom(DS1621_ADDR, 2);
|
||||
|
||||
if(Wire.available())
|
||||
data = Wire.receive() << 8;
|
||||
if(Wire.available())
|
||||
data |= Wire.receive();
|
||||
|
||||
Serial.print(data >> 8);
|
||||
|
||||
if(data & 0xff)
|
||||
Serial.print(",5");
|
||||
else
|
||||
Serial.print(",0");
|
||||
|
||||
Serial.println("");
|
||||
delay(1000);
|
||||
}
|
||||
|
|
@ -1,15 +0,0 @@
|
|||
float temp;
|
||||
int tempPin = 0;
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(9600);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
temp = analogRead(tempPin);
|
||||
temp = temp * 0.48828125;
|
||||
Serial.println(temp);
|
||||
delay(1000);
|
||||
}
|
||||
|
|
@ -1,71 +0,0 @@
|
|||
/*
|
||||
Web client
|
||||
|
||||
This sketch connects to a website (http://www.google.com)
|
||||
using an Arduino Wiznet Ethernet shield.
|
||||
|
||||
Circuit:
|
||||
* Ethernet shield attached to pins 10, 11, 12, 13
|
||||
|
||||
created 18 Dec 2009
|
||||
by David A. Mellis
|
||||
|
||||
*/
|
||||
|
||||
#include <SPI.h>
|
||||
#include <Ethernet.h>
|
||||
|
||||
// Enter a MAC address and IP address for your controller below.
|
||||
// The IP address will be dependent on your local network:
|
||||
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
|
||||
byte ip[] = { 192,168,1,23 };
|
||||
byte server[] = { 87,230,87,117 };
|
||||
|
||||
// Initialize the Ethernet client library
|
||||
// with the IP address and port of the server
|
||||
// that you want to connect to (port 80 is default for HTTP):
|
||||
Client client(server, 80);
|
||||
|
||||
void setup() {
|
||||
// start the Ethernet connection:
|
||||
Ethernet.begin(mac, ip);
|
||||
// start the serial library:
|
||||
Serial.begin(9600);
|
||||
// give the Ethernet shield a second to initialize:
|
||||
delay(1000);
|
||||
Serial.println("connecting...");
|
||||
|
||||
// if you get a connection, report back via serial:
|
||||
if (client.connect()) {
|
||||
Serial.println("connected");
|
||||
// Make a HTTP request:
|
||||
client.println("GET /search?q=arduino HTTP/1.0");
|
||||
client.println();
|
||||
}
|
||||
else {
|
||||
// kf you didn't get a connection to the server:
|
||||
Serial.println("connection failed");
|
||||
}
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
// if there are incoming bytes available
|
||||
// from the server, read them and print them:
|
||||
if (client.available()) {
|
||||
char c = client.read();
|
||||
Serial.print(c);
|
||||
}
|
||||
|
||||
// if the server's disconnected, stop the client:
|
||||
if (!client.connected()) {
|
||||
Serial.println();
|
||||
Serial.println("disconnecting.");
|
||||
client.stop();
|
||||
|
||||
// do nothing forevermore:
|
||||
for(;;)
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1,82 +0,0 @@
|
|||
/*
|
||||
Web Server
|
||||
|
||||
A simple web server that shows the value of the analog input pins.
|
||||
using an Arduino Wiznet Ethernet shield.
|
||||
|
||||
Circuit:
|
||||
* Ethernet shield attached to pins 10, 11, 12, 13
|
||||
* Analog inputs attached to pins A0 through A5 (optional)
|
||||
|
||||
created 18 Dec 2009
|
||||
by David A. Mellis
|
||||
modified 4 Sep 2010
|
||||
by Tom Igoe
|
||||
|
||||
*/
|
||||
|
||||
#include <SPI.h>
|
||||
#include <Ethernet.h>
|
||||
|
||||
// Enter a MAC address and IP address for your controller below.
|
||||
// The IP address will be dependent on your local network:
|
||||
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
|
||||
byte ip[] = { 192,168,1, 20 };
|
||||
|
||||
// Initialize the Ethernet server library
|
||||
// with the IP address and port you want to use
|
||||
// (port 80 is default for HTTP):
|
||||
Server server(80);
|
||||
|
||||
void setup()
|
||||
{
|
||||
// start the Ethernet connection and the server:
|
||||
Ethernet.begin(mac, ip);
|
||||
server.begin();
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
// listen for incoming clients
|
||||
Client client = server.available();
|
||||
if (client) {
|
||||
// an http request ends with a blank line
|
||||
boolean currentLineIsBlank = true;
|
||||
while (client.connected()) {
|
||||
if (client.available()) {
|
||||
char c = client.read();
|
||||
// if you've gotten to the end of the line (received a newline
|
||||
// character) and the line is blank, the http request has ended,
|
||||
// so you can send a reply
|
||||
if (c == '\n' && currentLineIsBlank) {
|
||||
// send a standard http response header
|
||||
client.println("HTTP/1.1 200 OK");
|
||||
client.println("Content-Type: text/html");
|
||||
client.println();
|
||||
|
||||
// output the value of each analog input pin
|
||||
for (int analogChannel = 0; analogChannel < 6; analogChannel++) {
|
||||
client.print("analog input ");
|
||||
client.print(analogChannel);
|
||||
client.print(" is ");
|
||||
client.print(analogRead(analogChannel));
|
||||
client.println("<br />");
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (c == '\n') {
|
||||
// you're starting a new line
|
||||
currentLineIsBlank = true;
|
||||
}
|
||||
else if (c != '\r') {
|
||||
// you've gotten a character on the current line
|
||||
currentLineIsBlank = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
// give the web browser time to receive the data
|
||||
delay(1);
|
||||
// close the connection:
|
||||
client.stop();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,14 +0,0 @@
|
|||
void setup()
|
||||
{
|
||||
Serial.begin(9600); // USB is always 12 Mbit/sec
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
digitalWrite(13, HIGH);
|
||||
Serial.println("Hello World...");
|
||||
delay(1000);
|
||||
digitalWrite(13, LOW);
|
||||
//Serial.println("Hello World...");
|
||||
delay(1000);
|
||||
}
|
||||
|
|
@ -1,18 +0,0 @@
|
|||
/*
|
||||
Blink
|
||||
Turns on an LED on for one second, then off for one second, repeatedly.
|
||||
|
||||
This example code is in the public domain.
|
||||
*/
|
||||
|
||||
void setup() {
|
||||
Serial.begin(9600);
|
||||
pinMode(13, OUTPUT);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
digitalWrite(13, HIGH); // set the LED on
|
||||
delay(1000); // wait for a second
|
||||
digitalWrite(13, LOW); // set the LED off
|
||||
delay(1000); // wait for a second
|
||||
}
|
||||
|
|
@ -1,27 +0,0 @@
|
|||
|
||||
void setup() {
|
||||
Serial.begin(9600);
|
||||
pinMode(11, OUTPUT);
|
||||
pinMode(12, OUTPUT);
|
||||
pinMode(13, OUTPUT);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
digitalWrite(11, LOW);
|
||||
digitalWrite(12, LOW);
|
||||
digitalWrite(13, LOW);
|
||||
|
||||
delay(100);
|
||||
|
||||
digitalWrite(11, HIGH);
|
||||
digitalWrite(12, LOW);
|
||||
digitalWrite(13, LOW);
|
||||
|
||||
delay(100);
|
||||
|
||||
digitalWrite(11, LOW);
|
||||
digitalWrite(12, HIGH);
|
||||
digitalWrite(13, LOW);
|
||||
|
||||
delay(100);
|
||||
}
|
||||
|
|
@ -1,33 +0,0 @@
|
|||
/*
|
||||
Blink
|
||||
Turns on an LED on for one second, then off for one second, repeatedly.
|
||||
|
||||
This example code is in the public domain.
|
||||
*/
|
||||
|
||||
void setup() {
|
||||
Serial.begin(9600);
|
||||
// initialize the digital pin as an output.
|
||||
// Pin 13 has an LED connected on most Arduino boards:
|
||||
pinMode(13, OUTPUT);
|
||||
pinMode(12, OUTPUT);
|
||||
pinMode(11, OUTPUT);
|
||||
pinMode(10, OUTPUT);
|
||||
pinMode(9, OUTPUT);
|
||||
pinMode(8, OUTPUT);
|
||||
pinMode(7, OUTPUT);
|
||||
pinMode(6, OUTPUT);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
digitalWrite(13, LOW); // set the LED on
|
||||
digitalWrite(12, HIGH); // set the LED on
|
||||
digitalWrite(11, LOW); // set the LED on
|
||||
digitalWrite(10, HIGH); // set the LED on
|
||||
digitalWrite(9, LOW); // set the LED on
|
||||
digitalWrite(8, LOW); // set the LED on
|
||||
digitalWrite(7, LOW); // set the LED on
|
||||
digitalWrite(6, LOW); // set the LED on
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -1,21 +0,0 @@
|
|||
int sensorPin = A0;
|
||||
int ledPin = 13;
|
||||
int sensorValue = 0;
|
||||
float printValue = 0;
|
||||
|
||||
void setup() {
|
||||
Serial.begin(9600);
|
||||
pinMode(ledPin, OUTPUT);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
sensorValue = analogRead(sensorPin);
|
||||
|
||||
printValue = (sensorValue * 0.48828125);
|
||||
|
||||
Serial.print(printValue);
|
||||
Serial.print("\n");
|
||||
digitalWrite(ledPin, HIGH);
|
||||
delay(1000);
|
||||
digitalWrite(ledPin, LOW);
|
||||
}
|
||||
|
|
@ -1,87 +0,0 @@
|
|||
#include "etherShield.h"
|
||||
|
||||
// please modify the following two lines. mac and ip have to be unique
|
||||
// in your local area network. You can not have the same numbers in
|
||||
// two devices:
|
||||
static uint8_t mymac[6] = {
|
||||
0x54,0x55,0x58,0x10,0x00,0x24};
|
||||
static uint8_t myip[4] = {
|
||||
192,168,1,20};
|
||||
// how did I get the mac addr? Translate the first 3 numbers into ascii is: TUX
|
||||
|
||||
#define BUFFER_SIZE 250
|
||||
unsigned char buf[BUFFER_SIZE+1];
|
||||
|
||||
uint16_t plen;
|
||||
|
||||
EtherShield es=EtherShield();
|
||||
|
||||
|
||||
void setup(){
|
||||
|
||||
|
||||
|
||||
/*initialize enc28j60*/
|
||||
es.ES_enc28j60Init(mymac);
|
||||
es.ES_enc28j60clkout(2); // change clkout from 6.25MHz to 12.5MHz
|
||||
|
||||
delay(10);
|
||||
|
||||
/* Magjack leds configuration, see enc28j60 datasheet, page 11 */
|
||||
// LEDA=green LEDB=yellow
|
||||
//
|
||||
// 0x880 is PHLCON LEDB=on, LEDA=on
|
||||
// enc28j60PhyWrite(PHLCON,0b0000 1000 1000 00 00);
|
||||
es.ES_enc28j60PhyWrite(PHLCON,0x880);
|
||||
delay(500);
|
||||
|
||||
//
|
||||
// 0x990 is PHLCON LEDB=off, LEDA=off
|
||||
// enc28j60PhyWrite(PHLCON,0b0000 1001 1001 00 00);
|
||||
es.ES_enc28j60PhyWrite(PHLCON,0x990);
|
||||
delay(500);
|
||||
|
||||
//
|
||||
// 0x880 is PHLCON LEDB=on, LEDA=on
|
||||
// enc28j60PhyWrite(PHLCON,0b0000 1000 1000 00 00);
|
||||
es.ES_enc28j60PhyWrite(PHLCON,0x880);
|
||||
delay(500);
|
||||
|
||||
//
|
||||
// 0x990 is PHLCON LEDB=off, LEDA=off
|
||||
// enc28j60PhyWrite(PHLCON,0b0000 1001 1001 00 00);
|
||||
es.ES_enc28j60PhyWrite(PHLCON,0x990);
|
||||
delay(500);
|
||||
|
||||
//
|
||||
// 0x476 is PHLCON LEDA=links status, LEDB=receive/transmit
|
||||
// enc28j60PhyWrite(PHLCON,0b0000 0100 0111 01 10);
|
||||
es.ES_enc28j60PhyWrite(PHLCON,0x476);
|
||||
delay(100);
|
||||
|
||||
//init the ethernet/ip layer:
|
||||
es.ES_init_ip_arp_udp_tcp(mymac,myip,80);
|
||||
|
||||
|
||||
}
|
||||
|
||||
void loop(){
|
||||
|
||||
plen = es.ES_enc28j60PacketReceive(BUFFER_SIZE, buf);
|
||||
|
||||
/*plen will be unequal to zero if there is a valid packet (without crc error) */
|
||||
if(plen!=0){
|
||||
if(es.ES_eth_type_is_arp_and_my_ip(buf,plen)){
|
||||
es.ES_make_arp_answer_from_request(buf);
|
||||
}
|
||||
// check if ip packets (icmp or udp) are for us:
|
||||
if(es.ES_eth_type_is_ip_and_my_ip(buf,plen)!=0){
|
||||
if(buf[IP_PROTO_P]==IP_PROTO_ICMP_V && buf[ICMP_TYPE_P]==ICMP_TYPE_ECHOREQUEST_V){
|
||||
// a ping packet, let's send pong
|
||||
|
||||
es.ES_make_echo_reply_from_request(buf,plen);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -1,221 +0,0 @@
|
|||
#include "etherShield.h"
|
||||
|
||||
// please modify the following two lines. mac and ip have to be unique
|
||||
// in your local area network. You can not have the same numbers in
|
||||
// two devices:
|
||||
static uint8_t mymac[6] = {0x54,0x55,0x58,0x10,0x00,0x24};
|
||||
static uint8_t myip[4] = {192,168,1,20};
|
||||
static char baseurl[]="http://192.168.1.15/";
|
||||
static uint16_t mywwwport =80; // listen port for tcp/www (max range 1-254)
|
||||
// or on a different port:
|
||||
//static char baseurl[]="http://10.0.0.24:88/";
|
||||
//static uint16_t mywwwport =88; // listen port for tcp/www (max range 1-254)
|
||||
//
|
||||
|
||||
int buttonState = 0;
|
||||
|
||||
#define BUFFER_SIZE 500
|
||||
static uint8_t buf[BUFFER_SIZE+1];
|
||||
#define STR_BUFFER_SIZE 22
|
||||
static char strbuf[STR_BUFFER_SIZE+1];
|
||||
|
||||
EtherShield es=EtherShield();
|
||||
|
||||
// prepare the webpage by writing the data to the tcp send buffer
|
||||
uint16_t print_webpage(uint8_t *buf);
|
||||
int8_t analyse_cmd(char *str);
|
||||
// get current temperature
|
||||
#define TEMP_PIN 3
|
||||
void getCurrentTemp( int *sign, int *whole, int *fract);
|
||||
|
||||
void setup(){
|
||||
|
||||
pinMode(7, INPUT);
|
||||
pinMode(2, OUTPUT);
|
||||
|
||||
/*initialize enc28j60*/
|
||||
es.ES_enc28j60Init(mymac);
|
||||
es.ES_enc28j60clkout(2); // change clkout from 6.25MHz to 12.5MHz
|
||||
delay(10);
|
||||
|
||||
/* Magjack leds configuration, see enc28j60 datasheet, page 11 */
|
||||
// LEDA=greed LEDB=yellow
|
||||
//
|
||||
// 0x880 is PHLCON LEDB=on, LEDA=on
|
||||
// enc28j60PhyWrite(PHLCON,0b0000 1000 1000 00 00);
|
||||
es.ES_enc28j60PhyWrite(PHLCON,0x880);
|
||||
delay(500);
|
||||
//
|
||||
// 0x990 is PHLCON LEDB=off, LEDA=off
|
||||
// enc28j60PhyWrite(PHLCON,0b0000 1001 1001 00 00);
|
||||
es.ES_enc28j60PhyWrite(PHLCON,0x990);
|
||||
delay(500);
|
||||
//
|
||||
// 0x880 is PHLCON LEDB=on, LEDA=on
|
||||
// enc28j60PhyWrite(PHLCON,0b0000 1000 1000 00 00);
|
||||
es.ES_enc28j60PhyWrite(PHLCON,0x880);
|
||||
delay(500);
|
||||
//
|
||||
// 0x990 is PHLCON LEDB=off, LEDA=off
|
||||
// enc28j60PhyWrite(PHLCON,0b0000 1001 1001 00 00);
|
||||
es.ES_enc28j60PhyWrite(PHLCON,0x990);
|
||||
delay(500);
|
||||
//
|
||||
// 0x476 is PHLCON LEDA=links status, LEDB=receive/transmit
|
||||
// enc28j60PhyWrite(PHLCON,0b0000 0100 0111 01 10);
|
||||
es.ES_enc28j60PhyWrite(PHLCON,0x476);
|
||||
delay(100);
|
||||
|
||||
//init the ethernet/ip layer:
|
||||
es.ES_init_ip_arp_udp_tcp(mymac,myip,80);
|
||||
|
||||
// initialize DS18B20 datapin
|
||||
digitalWrite(TEMP_PIN, LOW);
|
||||
pinMode(TEMP_PIN, INPUT); // sets the digital pin as input (logic 1)
|
||||
|
||||
|
||||
}
|
||||
|
||||
void loop(){
|
||||
uint16_t plen, dat_p;
|
||||
int8_t cmd;
|
||||
|
||||
plen = es.ES_enc28j60PacketReceive(BUFFER_SIZE, buf);
|
||||
|
||||
/*plen will ne unequal to zero if there is a valid packet (without crc error) */
|
||||
if(plen!=0){
|
||||
|
||||
// arp is broadcast if unknown but a host may also verify the mac address by sending it to a unicast address.
|
||||
if(es.ES_eth_type_is_arp_and_my_ip(buf,plen)){
|
||||
es.ES_make_arp_answer_from_request(buf);
|
||||
return;
|
||||
}
|
||||
|
||||
// check if ip packets are for us:
|
||||
if(es.ES_eth_type_is_ip_and_my_ip(buf,plen)==0){
|
||||
return;
|
||||
}
|
||||
|
||||
if(buf[IP_PROTO_P]==IP_PROTO_ICMP_V && buf[ICMP_TYPE_P]==ICMP_TYPE_ECHOREQUEST_V){
|
||||
es.ES_make_echo_reply_from_request(buf,plen);
|
||||
return;
|
||||
}
|
||||
|
||||
// tcp port www start, compare only the lower byte
|
||||
if (buf[IP_PROTO_P]==IP_PROTO_TCP_V&&buf[TCP_DST_PORT_H_P]==0&&buf[TCP_DST_PORT_L_P]==mywwwport){
|
||||
if (buf[TCP_FLAGS_P] & TCP_FLAGS_SYN_V){
|
||||
es.ES_make_tcp_synack_from_syn(buf); // make_tcp_synack_from_syn does already send the syn,ack
|
||||
return;
|
||||
}
|
||||
if (buf[TCP_FLAGS_P] & TCP_FLAGS_ACK_V){
|
||||
es.ES_init_len_info(buf); // init some data structures
|
||||
dat_p=es.ES_get_tcp_data_pointer();
|
||||
if (dat_p==0){ // we can possibly have no data, just ack:
|
||||
if (buf[TCP_FLAGS_P] & TCP_FLAGS_FIN_V){
|
||||
es.ES_make_tcp_ack_from_any(buf);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (strncmp("GET ",(char *)&(buf[dat_p]),4)!=0){
|
||||
// head, post and other methods for possible status codes see:
|
||||
// http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html
|
||||
plen=es.ES_fill_tcp_data_p(buf,0,PSTR("HTTP/1.0 200 OK\r\nContent-Type: text/html\r\n\r\n<h1>200 OK</h1>"));
|
||||
goto SENDTCP;
|
||||
}
|
||||
if (strncmp("/ ",(char *)&(buf[dat_p+4]),2)==0){
|
||||
plen=print_webpage(buf);
|
||||
goto SENDTCP;
|
||||
}
|
||||
cmd=analyse_cmd((char *)&(buf[dat_p+5]));
|
||||
if (cmd==1){
|
||||
plen=print_webpage(buf);
|
||||
}
|
||||
SENDTCP: es.ES_make_tcp_ack_from_any(buf); // send ack for http get
|
||||
es.ES_make_tcp_ack_with_data(buf,plen); // send data
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
// The returned value is stored in the global var strbuf
|
||||
uint8_t find_key_val(char *str,char *key)
|
||||
{
|
||||
uint8_t found=0;
|
||||
uint8_t i=0;
|
||||
char *kp;
|
||||
kp=key;
|
||||
while(*str && *str!=' ' && found==0){
|
||||
if (*str == *kp){
|
||||
kp++;
|
||||
if (*kp == '\0'){
|
||||
str++;
|
||||
kp=key;
|
||||
if (*str == '='){
|
||||
found=1;
|
||||
}
|
||||
}
|
||||
}else{
|
||||
kp=key;
|
||||
}
|
||||
str++;
|
||||
}
|
||||
if (found==1){
|
||||
// copy the value to a buffer and terminate it with '\0'
|
||||
while(*str && *str!=' ' && *str!='&' && i<STR_BUFFER_SIZE){
|
||||
strbuf[i]=*str;
|
||||
i++;
|
||||
str++;
|
||||
}
|
||||
strbuf[i]='\0';
|
||||
}
|
||||
return(found);
|
||||
}
|
||||
|
||||
int8_t analyse_cmd(char *str)
|
||||
{
|
||||
int8_t r=-1;
|
||||
|
||||
if (find_key_val(str,"cmd")){
|
||||
if (*strbuf < 0x3a && *strbuf > 0x2f){
|
||||
// is a ASCII number, return it
|
||||
r=(*strbuf-0x30);
|
||||
}
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
|
||||
uint16_t print_webpage(uint8_t *buf)
|
||||
{
|
||||
//char temp_string[1];
|
||||
int i=0;
|
||||
char *temp_string;
|
||||
|
||||
uint16_t plen;
|
||||
|
||||
buttonState = digitalRead(7);
|
||||
|
||||
if (buttonState == HIGH) {
|
||||
temp_string = "1";
|
||||
digitalWrite(2, HIGH);
|
||||
}
|
||||
else {
|
||||
temp_string = "0";
|
||||
digitalWrite(2, LOW);
|
||||
}
|
||||
Serial.println(buttonState, DEC);
|
||||
|
||||
plen=es.ES_fill_tcp_data_p(buf,0,PSTR("HTTP/1.0 200 OK\r\nContent-Type: text/html\r\n\r\n"));
|
||||
|
||||
while (temp_string[i]) {
|
||||
buf[TCP_CHECKSUM_L_P+3+plen]=temp_string[i++];
|
||||
plen++;
|
||||
}
|
||||
|
||||
return(plen);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
270
licht/licht.pde
270
licht/licht.pde
|
|
@ -1,270 +0,0 @@
|
|||
#define TSL_FREQ_PIN 2 // output use digital pin2 for interrupt
|
||||
#define TSL_S0 5
|
||||
#define TSL_S1 6
|
||||
#define TSL_S2 4
|
||||
#define TSL_S3 3
|
||||
#define TSL_LED 13
|
||||
|
||||
// 1000ms = 1s
|
||||
#define READ_TM 1000
|
||||
|
||||
unsigned long pulse_cnt = 0;
|
||||
|
||||
// two variables used to track time
|
||||
unsigned long cur_tm = millis();
|
||||
unsigned long pre_tm = cur_tm;
|
||||
|
||||
// we'll need to access the amount
|
||||
// of time passed
|
||||
unsigned int tm_diff = 0;
|
||||
|
||||
// need to measure what to divide freq by
|
||||
// 1x sensitivity = 10,
|
||||
// 10x sens = 100,
|
||||
// 100x sens = 1000
|
||||
int calc_sensitivity = 10;
|
||||
|
||||
// set our frequency multiplier to a default of 1
|
||||
// which maps to output frequency scaling of 100x
|
||||
int freq_mult = 100;
|
||||
|
||||
|
||||
void setup() {
|
||||
|
||||
Serial.begin(9600);
|
||||
|
||||
// attach interrupt to pin2, send output pin of TSL230R to arduino 2
|
||||
// call handler on each rising pulse
|
||||
|
||||
attachInterrupt(0, add_pulse, RISING);
|
||||
|
||||
pinMode(TSL_FREQ_PIN, INPUT);
|
||||
pinMode(TSL_S0, OUTPUT);
|
||||
pinMode(TSL_S1, OUTPUT);
|
||||
pinMode(TSL_S2, OUTPUT);
|
||||
pinMode(TSL_S3, OUTPUT);
|
||||
pinMode(TSL_LED, OUTPUT);
|
||||
|
||||
digitalWrite(TSL_S0, HIGH);
|
||||
digitalWrite(TSL_S1, LOW);
|
||||
digitalWrite(TSL_S2, HIGH);
|
||||
digitalWrite(TSL_S3, HIGH);
|
||||
digitalWrite(TSL_LED, LOW);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
||||
// check the value of the light sensor every READ_TM ms
|
||||
|
||||
// calculate how much time has passed
|
||||
|
||||
pre_tm = cur_tm;
|
||||
cur_tm = millis();
|
||||
|
||||
if( cur_tm > pre_tm ) {
|
||||
tm_diff += cur_tm - pre_tm;
|
||||
}
|
||||
else if( cur_tm < pre_tm ) {
|
||||
// handle overflow and rollover (Arduino 011)
|
||||
tm_diff += ( cur_tm + ( 34359737 - pre_tm ));
|
||||
}
|
||||
|
||||
// if enough time has passed to do a new reading...
|
||||
|
||||
if( tm_diff >= READ_TM ) {
|
||||
|
||||
// re-set the ms counter
|
||||
tm_diff = 0;
|
||||
|
||||
// get our current frequency reading
|
||||
unsigned long frequency = get_tsl_freq();
|
||||
|
||||
// calculate radiant energy
|
||||
float uw_cm2 = calc_uwatt_cm2( frequency );
|
||||
|
||||
// calculate illuminance
|
||||
float lux = calc_lux_single( uw_cm2, 0.175 );
|
||||
//print(lux);
|
||||
Serial.print(lux, DEC);
|
||||
|
||||
|
||||
Serial.print("\n");
|
||||
/*
|
||||
Serial.print("tm_diff: ");
|
||||
Serial.print(tm_diff, DEC);
|
||||
Serial.print(" pulse_cnt: ");
|
||||
Serial.print(pulse_cnt, DEC);
|
||||
Serial.print("\n");
|
||||
*/
|
||||
if(lux < 400) {
|
||||
//Serial.print("off\n");
|
||||
//digitalWrite(TSL_LED, HIGH);
|
||||
//Serial.print(1, BYTE);
|
||||
} else {
|
||||
//digitalWrite(TSL_LED, LOW);
|
||||
//Serial.print(0, BYTE);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void set_scaling ( int what ) {
|
||||
|
||||
// set output frequency scaling
|
||||
// adjust frequency multiplier and set proper pin values
|
||||
// e.g.:
|
||||
// scale = 2 == freq_mult = 2
|
||||
// scale = 10 == freq_mult = 10
|
||||
// scale = 100 == freq_mult = 100
|
||||
|
||||
int pin_2 = HIGH;
|
||||
int pin_3 = HIGH;
|
||||
|
||||
switch( what ) {
|
||||
case 2:
|
||||
pin_3 = LOW;
|
||||
freq_mult = 2;
|
||||
break;
|
||||
case 10:
|
||||
pin_2 = LOW;
|
||||
freq_mult = 10;
|
||||
break;
|
||||
case 100:
|
||||
freq_mult = 100;
|
||||
break;
|
||||
default:
|
||||
// don't do anything with levels
|
||||
// we don't recognize
|
||||
return;
|
||||
}
|
||||
|
||||
// set the pins to their appropriate levels
|
||||
|
||||
digitalWrite(TSL_S2, pin_2);
|
||||
digitalWrite(TSL_S3, pin_3);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
unsigned long get_tsl_freq() {
|
||||
|
||||
// we have to scale out the frequency --
|
||||
// Scaling on the TSL230R requires us to multiply by a factor
|
||||
// to get actual frequency
|
||||
|
||||
unsigned long freq = pulse_cnt * freq_mult;
|
||||
|
||||
// reset the pulse counter
|
||||
|
||||
pulse_cnt = 0;
|
||||
|
||||
return(freq);
|
||||
}
|
||||
|
||||
void add_pulse() {
|
||||
|
||||
// increase pulse count
|
||||
pulse_cnt++;
|
||||
return;
|
||||
}
|
||||
|
||||
void sensitivity( bool dir ) {
|
||||
|
||||
// adjust sensitivity in 3 steps of 10x either direction
|
||||
|
||||
int pin_0;
|
||||
int pin_1;
|
||||
|
||||
if( dir == true ) {
|
||||
|
||||
// increasing sensitivity
|
||||
|
||||
// -- already as high as we can get
|
||||
if( calc_sensitivity == 1000 )
|
||||
return;
|
||||
|
||||
if( calc_sensitivity == 100 ) {
|
||||
// move up to max sensitivity
|
||||
pin_0 = true;
|
||||
pin_1 = true;
|
||||
}
|
||||
else {
|
||||
// move up to med. sesitivity
|
||||
pin_0 = false;
|
||||
pin_1 = true;
|
||||
}
|
||||
|
||||
// increase sensitivity divider
|
||||
calc_sensitivity *= 10;
|
||||
}
|
||||
else {
|
||||
// reducing sensitivity
|
||||
|
||||
// already at lowest setting
|
||||
|
||||
if( calc_sensitivity == 10 )
|
||||
return;
|
||||
|
||||
if( calc_sensitivity == 100 ) {
|
||||
// move to lowest setting
|
||||
pin_0 = true;
|
||||
pin_1 = false;
|
||||
}
|
||||
else {
|
||||
// move to medium sensitivity
|
||||
pin_0 = false;
|
||||
pin_1 = true;
|
||||
}
|
||||
|
||||
// reduce sensitivity divider
|
||||
calc_sensitivity = calc_sensitivity / 10;
|
||||
}
|
||||
|
||||
// make any necessary changes to pin states
|
||||
|
||||
digitalWrite(TSL_S0, pin_0);
|
||||
digitalWrite(TSL_S1, pin_1);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
float calc_uwatt_cm2(unsigned long freq) {
|
||||
|
||||
// get uW observed - assume 640nm wavelength
|
||||
// calc_sensitivity is our divide-by to map to a given signal strength
|
||||
// for a given sensitivity (each level of greater sensitivity reduces the signal
|
||||
// (uW) by a factor of 10)
|
||||
|
||||
float uw_cm2 = (float) freq / (float) calc_sensitivity;
|
||||
|
||||
// extrapolate into entire cm2 area
|
||||
|
||||
uw_cm2 *= ( (float) 1 / (float) 0.0136 );
|
||||
|
||||
return(uw_cm2);
|
||||
|
||||
}
|
||||
|
||||
float calc_lux_single(float uw_cm2, float efficiency) {
|
||||
|
||||
// calculate lux (lm/m^2), using standard formula:
|
||||
// Xv = Xl * V(l) * Km
|
||||
// Xl is W/m^2 (calculate actual receied uW/cm^2, extrapolate from sensor size (0.0136cm^2)
|
||||
// to whole cm size, then convert uW to W)
|
||||
// V(l) = efficiency function (provided via argument)
|
||||
// Km = constant, lm/W @ 555nm = 683 (555nm has efficiency function of nearly 1.0)
|
||||
//
|
||||
// Only a single wavelength is calculated - you'd better make sure that your
|
||||
// source is of a single wavelength... Otherwise, you should be using
|
||||
// calc_lux_gauss() for multiple wavelengths
|
||||
|
||||
// convert to w_m2
|
||||
float w_m2 = (uw_cm2 / (float) 1000000) * (float) 100;
|
||||
|
||||
// calculate lux
|
||||
float lux = w_m2 * efficiency * (float) 683;
|
||||
|
||||
return(lux);
|
||||
}
|
||||
|
||||
|
||||
246
light.c
246
light.c
|
|
@ -1,246 +0,0 @@
|
|||
#define TSL_FREQ_PIN 2 // output use digital pin2 for interrupt
|
||||
#define TSL_S0 5
|
||||
#define TSL_S1 6
|
||||
#define TSL_S2 7
|
||||
#define TSL_S3 8
|
||||
|
||||
// 1000ms = 1s
|
||||
#define READ_TM 1000
|
||||
|
||||
unsigned long pulse_cnt = 0;
|
||||
|
||||
// two variables used to track time
|
||||
unsigned long cur_tm = millis();
|
||||
unsigned long pre_tm = cur_tm;
|
||||
|
||||
// we'll need to access the amount
|
||||
// of time passed
|
||||
unsigned int tm_diff = 0;
|
||||
|
||||
// need to measure what to divide freq by
|
||||
// 1x sensitivity = 10,
|
||||
// 10x sens = 100,
|
||||
// 100x sens = 1000
|
||||
int calc_sensitivity = 10;
|
||||
|
||||
// set our frequency multiplier to a default of 1
|
||||
// which maps to output frequency scaling of 100x
|
||||
int freq_mult = 100;
|
||||
|
||||
|
||||
void setup() {
|
||||
|
||||
// attach interrupt to pin2, send output pin of TSL230R to arduino 2
|
||||
// call handler on each rising pulse
|
||||
|
||||
attachInterrupt(0, add_pulse, RISING);
|
||||
|
||||
pinMode(TSL_FREQ_PIN, INPUT);
|
||||
pinMode(TSL_S0, OUTPUT);
|
||||
pinMode(TSL_S1, OUTPUT);
|
||||
pinMode(TSL_S2, OUTPUT);
|
||||
pinMode(TSL_S3, OUTPUT);
|
||||
|
||||
digitalWrite(TSL_S0, HIGH);
|
||||
digitalWrite(TSL_S1, LOW);
|
||||
digitalWrite(TSL_S2, HIGH);
|
||||
digitalWrite(TSL_S3, HIGH);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
||||
// check the value of the light sensor every READ_TM ms
|
||||
|
||||
// calculate how much time has passed
|
||||
|
||||
pre_tm = cur_tm;
|
||||
cur_tm = millis();
|
||||
|
||||
if( cur_tm > pre_tm ) {
|
||||
tm_diff += cur_tm - pre_tm;
|
||||
}
|
||||
else if( cur_tm < pre_tm ) {
|
||||
// handle overflow and rollover (Arduino 011)
|
||||
tm_diff += ( cur_tm + ( 34359737 - pre_tm ));
|
||||
}
|
||||
|
||||
// if enough time has passed to do a new reading...
|
||||
|
||||
if( tm_diff >= READ_TM ) {
|
||||
|
||||
// re-set the ms counter
|
||||
tm_diff = 0;
|
||||
|
||||
// get our current frequency reading
|
||||
unsigned long frequency = get_tsl_freq();
|
||||
|
||||
// calculate radiant energy
|
||||
float uw_cm2 = calc_uwcm2( frequency );
|
||||
|
||||
// calculate illuminance
|
||||
float lux = calc_lux_single( uw_cm2, 0.175 );
|
||||
print(lux);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void set_scaling ( int what ) {
|
||||
|
||||
// set output frequency scaling
|
||||
// adjust frequency multiplier and set proper pin values
|
||||
// e.g.:
|
||||
// scale = 2 == freq_mult = 2
|
||||
// scale = 10 == freq_mult = 10
|
||||
// scale = 100 == freq_mult = 100
|
||||
|
||||
int pin_2 = HIGH;
|
||||
int pin_3 = HIGH;
|
||||
|
||||
switch( what ) {
|
||||
case 2:
|
||||
pin_3 = LOW;
|
||||
freq_mult = 2;
|
||||
break;
|
||||
case 10:
|
||||
pin_2 = LOW;
|
||||
freq_mult = 10;
|
||||
break;
|
||||
case 100:
|
||||
freq_mult = 100;
|
||||
break;
|
||||
default:
|
||||
// don't do anything with levels
|
||||
// we don't recognize
|
||||
return;
|
||||
}
|
||||
|
||||
// set the pins to their appropriate levels
|
||||
|
||||
digitalWrite(TSL_S2, pin_2);
|
||||
digitalWrite(TSL_S3, pin_3);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
unsigned long get_tsl_freq() {
|
||||
|
||||
// we have to scale out the frequency --
|
||||
// Scaling on the TSL230R requires us to multiply by a factor
|
||||
// to get actual frequency
|
||||
|
||||
unsigned long freq = pulse_cnt * freq_mult;
|
||||
|
||||
// reset the pulse counter
|
||||
|
||||
pulse_cnt = 0;
|
||||
|
||||
return(freq);
|
||||
}
|
||||
|
||||
void add_pulse() {
|
||||
|
||||
// increase pulse count
|
||||
pulse_cnt++;
|
||||
return;
|
||||
}
|
||||
|
||||
void sensitivity( bool dir ) {
|
||||
|
||||
// adjust sensitivity in 3 steps of 10x either direction
|
||||
|
||||
int pin_0;
|
||||
int pin_1;
|
||||
|
||||
if( dir == true ) {
|
||||
|
||||
// increasing sensitivity
|
||||
|
||||
// -- already as high as we can get
|
||||
if( calc_sensitivity == 1000 )
|
||||
return;
|
||||
|
||||
if( calc_sensitivity == 100 ) {
|
||||
// move up to max sensitivity
|
||||
pin_0 = true;
|
||||
pin_1 = true;
|
||||
}
|
||||
else {
|
||||
// move up to med. sesitivity
|
||||
pin_0 = false;
|
||||
pin_1 = true;
|
||||
}
|
||||
|
||||
// increase sensitivity divider
|
||||
calc_sensitivity *= 10;
|
||||
}
|
||||
else {
|
||||
// reducing sensitivity
|
||||
|
||||
// already at lowest setting
|
||||
|
||||
if( calc_sensitivity == 10 )
|
||||
return;
|
||||
|
||||
if( calc_sensitivity == 100 ) {
|
||||
// move to lowest setting
|
||||
pin_0 = true;
|
||||
pin_1 = false;
|
||||
}
|
||||
else {
|
||||
// move to medium sensitivity
|
||||
pin_0 = false;
|
||||
pin_1 = true;
|
||||
}
|
||||
|
||||
// reduce sensitivity divider
|
||||
calc_sensitivity = calc_sensitivity / 10;
|
||||
}
|
||||
|
||||
// make any necessary changes to pin states
|
||||
|
||||
digitalWrite(TSL_S0, pin_0);
|
||||
digitalWrite(TSL_S1, pin_1);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
float calc_uwatt_cm2(unsigned long freq) {
|
||||
|
||||
// get uW observed - assume 640nm wavelength
|
||||
// calc_sensitivity is our divide-by to map to a given signal strength
|
||||
// for a given sensitivity (each level of greater sensitivity reduces the signal
|
||||
// (uW) by a factor of 10)
|
||||
|
||||
float uw_cm2 = (float) freq / (float) calc_sensitivity;
|
||||
|
||||
// extrapolate into entire cm2 area
|
||||
|
||||
uw_cm2 *= ( (float) 1 / (float) 0.0136 );
|
||||
|
||||
return(uw_cm2);
|
||||
|
||||
}
|
||||
|
||||
float calc_lux_single(float uw_cm2, float efficiency) {
|
||||
|
||||
// calculate lux (lm/m^2), using standard formula:
|
||||
// Xv = Xl * V(l) * Km
|
||||
// Xl is W/m^2 (calculate actual receied uW/cm^2, extrapolate from sensor size (0.0136cm^2)
|
||||
// to whole cm size, then convert uW to W)
|
||||
// V(l) = efficiency function (provided via argument)
|
||||
// Km = constant, lm/W @ 555nm = 683 (555nm has efficiency function of nearly 1.0)
|
||||
//
|
||||
// Only a single wavelength is calculated - you'd better make sure that your
|
||||
// source is of a single wavelength... Otherwise, you should be using
|
||||
// calc_lux_gauss() for multiple wavelengths
|
||||
|
||||
// convert to w_m2
|
||||
float w_m2 = (u_cm2 / (float) 1000000) * (float) 100;
|
||||
|
||||
// calculate lux
|
||||
float lux = w_m2 * efficiency * (float) 683;
|
||||
|
||||
return(lux);
|
||||
}
|
||||
|
||||
|
||||
37
light.txt
37
light.txt
|
|
@ -1,37 +0,0 @@
|
|||
1. #define TSL_FREQ_PIN 2 // output use digital pin2 for interrupt
|
||||
2. #define TSL_S0 5
|
||||
3. #define TSL_S1 6
|
||||
4. #define TSL_S2 7
|
||||
5. #define TSL_S3 8
|
||||
|
||||
1. unsigned long pulse_cnt = 0;
|
||||
2.
|
||||
3. void setup() {
|
||||
4.
|
||||
5. // attach interrupt to pin2, send output pin of TSL230R to arduino 2
|
||||
6. // call handler on each rising pulse
|
||||
7.
|
||||
8. attachInterrupt(0, add_pulse, RISING);
|
||||
9.
|
||||
10. pinMode(TSL_FREQ_PIN, INPUT);
|
||||
11. pinMode(TSL_S0, OUTPUT);
|
||||
12. pinMode(TSL_S1, OUTPUT);
|
||||
13. pinMode(TSL_S2, OUTPUT);
|
||||
14. pinMode(TSL_S3, OUTPUT);
|
||||
15.
|
||||
16. digitalWrite(TSL_S0, HIGH);
|
||||
17. digitalWrite(TSL_S1, LOW);
|
||||
18. digitalWrite(TSL_S2, HIGH);
|
||||
19. digitalWrite(TSL_S3, HIGH);
|
||||
20. }
|
||||
21.
|
||||
22. void loop() {
|
||||
23.
|
||||
24. }
|
||||
25.
|
||||
26. void add_pulse() {
|
||||
27.
|
||||
28. // increase pulse count
|
||||
29. pulse_cnt++;
|
||||
30. return;
|
||||
31. }
|
||||
|
|
@ -1,21 +0,0 @@
|
|||
#include <LiquidCrystal.h>
|
||||
|
||||
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
|
||||
|
||||
float temp;
|
||||
int tempPin = 0;
|
||||
|
||||
void setup() {
|
||||
lcd.begin(16, 2);
|
||||
lcd.print("Temperature:");
|
||||
}
|
||||
|
||||
void loop() {
|
||||
temp = analogRead(tempPin);
|
||||
temp = temp * 0.48828125;
|
||||
//temp = (5.0 * temp * 100.0)/1024.0;
|
||||
lcd.setCursor(0, 1);
|
||||
lcd.print(temp);
|
||||
delay(1000);
|
||||
}
|
||||
|
||||
|
|
@ -1,225 +0,0 @@
|
|||
#include <TimerOne.h>
|
||||
#include <MatrixFonts3x5.h>
|
||||
|
||||
#define COLS 5
|
||||
#define ROWS 7
|
||||
#define PINS 13
|
||||
|
||||
#define MATRIX1 { \
|
||||
{1,0,1,0,1,0,1}, \
|
||||
{0,1,0,1,0,1,0}, \
|
||||
{1,0,1,0,1,0,1}, \
|
||||
{0,1,0,1,0,1,0}, \
|
||||
{1,0,1,0,1,0,1} \
|
||||
}
|
||||
|
||||
#define MATRIX2 { \
|
||||
{0,1,0,1,0,1,0}, \
|
||||
{1,0,1,0,1,0,1}, \
|
||||
{0,1,0,1,0,1,0}, \
|
||||
{1,0,1,0,1,0,1}, \
|
||||
{0,1,0,1,0,1,0} \
|
||||
}
|
||||
|
||||
byte col = 0;
|
||||
byte leds[COLS][ROWS];
|
||||
|
||||
// pin[xx] on led matrix connected to nn on Arduino (-1 is dummy to make array start at pos 1)
|
||||
int pins[PINS]= {-1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12};
|
||||
|
||||
// col[xx] of leds = pin yy on led matrix
|
||||
int cols[COLS] = {pins[1], pins[3], pins[10], pins[7], pins[8]};
|
||||
|
||||
// row[xx] of leds = pin yy on led matrix
|
||||
int rows[ROWS] = {pins[12], pins[11], pins[2], pins[9], pins[4], pins[5], pins[6]};
|
||||
|
||||
const int numPatterns = 16;
|
||||
byte patterns[numPatterns][COLS][ROWS] = {H,A,L,L,O,DASH,H,E,L,M,U,T,SPACE,MATRIX1,MATRIX2,MATRIX1};
|
||||
|
||||
int pattern = 0;
|
||||
|
||||
void setup() {
|
||||
|
||||
//Serial.begin(9600);
|
||||
|
||||
// sets the pins as output
|
||||
for (int i = 0; i < PINS; i++) {
|
||||
pinMode(pins[i], OUTPUT);
|
||||
}
|
||||
|
||||
// set up cols
|
||||
for (int i = 1; i <= COLS; i++) {
|
||||
digitalWrite(cols[i - 1], 0);
|
||||
}
|
||||
// and rows
|
||||
for (int i = 1; i <= ROWS; i++) {
|
||||
digitalWrite(rows[i - 1], 1);
|
||||
}
|
||||
|
||||
blink();
|
||||
five2one();
|
||||
|
||||
clearLeds();
|
||||
|
||||
Timer1.initialize(2000); // initialize timer1, and set a 1/2 second period
|
||||
Timer1.attachInterrupt(display); // attaches display() as a timer overflow interrupt
|
||||
|
||||
setPattern(pattern);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
pattern = ++pattern % numPatterns;
|
||||
slidePattern(pattern, 120);
|
||||
}
|
||||
// Interrupt routine
|
||||
void display() {
|
||||
digitalWrite(cols[col], 0); // Turn whole previous column off
|
||||
col++;
|
||||
if (col == 5) {
|
||||
col = 0;
|
||||
}
|
||||
for (int row = 0; row < 7; row++) {
|
||||
if (leds[col][(ROWS - 1) - row] == 1) {
|
||||
digitalWrite(rows[row], 0); // Turn on this led
|
||||
}
|
||||
else {
|
||||
digitalWrite(rows[row], 1); // Turn off this led
|
||||
}
|
||||
// delay(10);
|
||||
}
|
||||
digitalWrite(cols[col], 1); // Turn whole column on at once (for equal lighting times)
|
||||
|
||||
}
|
||||
|
||||
void slidePattern(int pattern, int del) {
|
||||
for (int l = 0; l < COLS; l++) {
|
||||
for (int i = 0; i < (COLS - 1); i++) {
|
||||
for (int j = 0; j < ROWS; j++) {
|
||||
leds[i][j] = leds[i + 1][j];
|
||||
}
|
||||
}
|
||||
for (int j = 0; j < ROWS; j++) {
|
||||
leds[4][j] = patterns[pattern][0 + l][j];
|
||||
}
|
||||
delay(del);
|
||||
}
|
||||
}
|
||||
|
||||
void clearLeds() {
|
||||
// Clear display array
|
||||
for (int i = 0; i < COLS; i++) {
|
||||
for (int j = 0; j < ROWS; j++) {
|
||||
leds[i][j] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void setPattern(int pattern) {
|
||||
for (int i = 0; i < COLS; i++) {
|
||||
for (int j = 0; j < ROWS; j++) {
|
||||
leds[i][j] = patterns[pattern][i][j];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void blink() {
|
||||
for(int i = 0; i < 12; i++) {
|
||||
if(i % 2 != 0) {
|
||||
digitalWrite(cols[0], 1);
|
||||
digitalWrite(cols[1], 0);
|
||||
digitalWrite(cols[2], 0);
|
||||
digitalWrite(cols[3], 0);
|
||||
digitalWrite(cols[4], 0);
|
||||
digitalWrite(rows[0], 0);
|
||||
digitalWrite(rows[1], 1);
|
||||
digitalWrite(rows[2], 1);
|
||||
digitalWrite(rows[3], 1);
|
||||
digitalWrite(rows[4], 1);
|
||||
digitalWrite(rows[5], 1);
|
||||
digitalWrite(rows[6], 1);
|
||||
} else {
|
||||
digitalWrite(cols[0], 0);
|
||||
digitalWrite(cols[1], 0);
|
||||
digitalWrite(cols[2], 0);
|
||||
digitalWrite(cols[3], 0);
|
||||
digitalWrite(cols[4], 0);
|
||||
digitalWrite(rows[0], 1);
|
||||
digitalWrite(rows[1], 1);
|
||||
digitalWrite(rows[2], 1);
|
||||
digitalWrite(rows[3], 1);
|
||||
digitalWrite(rows[4], 1);
|
||||
digitalWrite(rows[5], 1);
|
||||
digitalWrite(rows[6], 1);
|
||||
}
|
||||
delay(100);
|
||||
}
|
||||
}
|
||||
|
||||
void five2one() {
|
||||
digitalWrite(cols[0], 1);
|
||||
digitalWrite(cols[1], 0);
|
||||
digitalWrite(cols[2], 0);
|
||||
digitalWrite(cols[3], 0);
|
||||
digitalWrite(cols[4], 0);
|
||||
digitalWrite(rows[0], 0);
|
||||
digitalWrite(rows[1], 1);
|
||||
digitalWrite(rows[2], 1);
|
||||
digitalWrite(rows[3], 1);
|
||||
digitalWrite(rows[4], 1);
|
||||
digitalWrite(rows[5], 1);
|
||||
digitalWrite(rows[6], 1);
|
||||
delay(100);
|
||||
digitalWrite(cols[0], 0);
|
||||
digitalWrite(cols[1], 1);
|
||||
digitalWrite(cols[2], 0);
|
||||
digitalWrite(cols[3], 0);
|
||||
digitalWrite(cols[4], 0);
|
||||
digitalWrite(rows[0], 0);
|
||||
digitalWrite(rows[1], 1);
|
||||
digitalWrite(rows[2], 1);
|
||||
digitalWrite(rows[3], 1);
|
||||
digitalWrite(rows[4], 1);
|
||||
digitalWrite(rows[5], 1);
|
||||
digitalWrite(rows[6], 1);
|
||||
delay(100);
|
||||
digitalWrite(cols[0], 0);
|
||||
digitalWrite(cols[1], 0);
|
||||
digitalWrite(cols[2], 1);
|
||||
digitalWrite(cols[3], 0);
|
||||
digitalWrite(cols[4], 0);
|
||||
digitalWrite(rows[0], 0);
|
||||
digitalWrite(rows[1], 1);
|
||||
digitalWrite(rows[2], 1);
|
||||
digitalWrite(rows[3], 1);
|
||||
digitalWrite(rows[4], 1);
|
||||
digitalWrite(rows[5], 1);
|
||||
digitalWrite(rows[6], 1);
|
||||
delay(100);
|
||||
digitalWrite(cols[0], 0);
|
||||
digitalWrite(cols[1], 0);
|
||||
digitalWrite(cols[2], 0);
|
||||
digitalWrite(cols[3], 1);
|
||||
digitalWrite(cols[4], 0);
|
||||
digitalWrite(rows[0], 0);
|
||||
digitalWrite(rows[1], 1);
|
||||
digitalWrite(rows[2], 1);
|
||||
digitalWrite(rows[3], 1);
|
||||
digitalWrite(rows[4], 1);
|
||||
digitalWrite(rows[5], 1);
|
||||
digitalWrite(rows[6], 1);
|
||||
delay(100);
|
||||
digitalWrite(cols[0], 0);
|
||||
digitalWrite(cols[1], 0);
|
||||
digitalWrite(cols[2], 0);
|
||||
digitalWrite(cols[3], 0);
|
||||
digitalWrite(cols[4], 1);
|
||||
digitalWrite(rows[0], 0);
|
||||
digitalWrite(rows[1], 1);
|
||||
digitalWrite(rows[2], 1);
|
||||
digitalWrite(rows[3], 1);
|
||||
digitalWrite(rows[4], 1);
|
||||
digitalWrite(rows[5], 1);
|
||||
digitalWrite(rows[6], 1);
|
||||
delay(100);
|
||||
}
|
||||
|
||||
|
|
@ -1,162 +0,0 @@
|
|||
#include <TimerOne.h>
|
||||
|
||||
#define COLS 5
|
||||
#define ROWS 7
|
||||
#define PINS 13
|
||||
|
||||
#define SPACE { \
|
||||
{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, 0, 0}, \
|
||||
{0, 0, 0, 0, 0} \
|
||||
}
|
||||
|
||||
#define H { \
|
||||
{1, 0, 0, 0, 1}, \
|
||||
{1, 0, 0, 0, 1}, \
|
||||
{1, 0, 0, 0, 1}, \
|
||||
{1, 1, 1, 1, 1}, \
|
||||
{1, 0, 0, 0, 1}, \
|
||||
{1, 0, 0, 0, 1}, \
|
||||
{1, 0, 0, 0, 1} \
|
||||
}
|
||||
|
||||
#define E { \
|
||||
{1, 1, 1, 1, 1}, \
|
||||
{1, 0, 0, 0, 0}, \
|
||||
{1, 0, 0, 0, 0}, \
|
||||
{1, 1, 1, 1, 0}, \
|
||||
{1, 0, 0, 0, 0}, \
|
||||
{1, 0, 0, 0, 0}, \
|
||||
{1, 1, 1, 1, 1} \
|
||||
}
|
||||
|
||||
#define L { \
|
||||
{1, 0, 0, 0, 0}, \
|
||||
{1, 0, 0, 0, 0}, \
|
||||
{1, 0, 0, 0, 0}, \
|
||||
{1, 0, 0, 0, 0}, \
|
||||
{1, 0, 0, 0, 0}, \
|
||||
{1, 0, 0, 0, 0}, \
|
||||
{1, 1, 1, 1, 1} \
|
||||
}
|
||||
|
||||
byte col = 0;
|
||||
byte leds[COLS][ROWS];
|
||||
|
||||
// pin[xx] on led matrix connected to nn on Arduino (-1 is dummy to make array start at pos 1)
|
||||
int pins[PINS]= {-1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12};
|
||||
|
||||
// col[xx] of leds = pin yy on led matrix
|
||||
int cols[COLS] = {pins[1], pins[3], pins[10], pins[7], pins[8]};
|
||||
|
||||
// row[xx] of leds = pin yy on led matrix
|
||||
int rows[ROWS] = {pins[12], pins[11], pins[2], pins[9], pins[4], pins[5], pins[6]};
|
||||
|
||||
|
||||
void setup() {
|
||||
|
||||
Serial.begin(9600);
|
||||
|
||||
for (int i = 0; i < PINS; i++) {
|
||||
pinMode(pins[i], OUTPUT);
|
||||
}
|
||||
for (int i = 1; i <= COLS; i++) {
|
||||
digitalWrite(cols[i - 1], 0);
|
||||
}
|
||||
for (int i = 1; i <= ROWS; i++) {
|
||||
digitalWrite(rows[i - 1], 1);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
digitalWrite(cols[0], 0);
|
||||
digitalWrite(cols[1], 1);
|
||||
digitalWrite(cols[2], 0);
|
||||
digitalWrite(cols[3], 0);
|
||||
digitalWrite(cols[4], 0);
|
||||
digitalWrite(rows[0], 0);
|
||||
digitalWrite(rows[1], 1);
|
||||
digitalWrite(rows[2], 1);
|
||||
digitalWrite(rows[3], 1);
|
||||
digitalWrite(rows[4], 1);
|
||||
digitalWrite(rows[5], 1);
|
||||
digitalWrite(rows[6], 1);
|
||||
delay(2000);
|
||||
digitalWrite(cols[0], 0);
|
||||
digitalWrite(cols[1], 0);
|
||||
digitalWrite(cols[2], 1);
|
||||
digitalWrite(cols[3], 0);
|
||||
digitalWrite(cols[4], 0);
|
||||
digitalWrite(rows[0], 0);
|
||||
digitalWrite(rows[1], 1);
|
||||
digitalWrite(rows[2], 1);
|
||||
digitalWrite(rows[3], 1);
|
||||
digitalWrite(rows[4], 1);
|
||||
digitalWrite(rows[5], 1);
|
||||
digitalWrite(rows[6], 1);
|
||||
delay(2000);
|
||||
digitalWrite(cols[0], 0);
|
||||
digitalWrite(cols[1], 0);
|
||||
digitalWrite(cols[2], 0);
|
||||
digitalWrite(cols[3], 1);
|
||||
digitalWrite(cols[4], 0);
|
||||
digitalWrite(rows[0], 0);
|
||||
digitalWrite(rows[1], 1);
|
||||
digitalWrite(rows[2], 1);
|
||||
digitalWrite(rows[3], 1);
|
||||
digitalWrite(rows[4], 1);
|
||||
digitalWrite(rows[5], 1);
|
||||
digitalWrite(rows[6], 1);
|
||||
delay(2000);
|
||||
digitalWrite(cols[0], 0);
|
||||
digitalWrite(cols[1], 0);
|
||||
digitalWrite(cols[2], 0);
|
||||
digitalWrite(cols[3], 0);
|
||||
digitalWrite(cols[4], 1);
|
||||
digitalWrite(rows[0], 0);
|
||||
digitalWrite(rows[1], 1);
|
||||
digitalWrite(rows[2], 1);
|
||||
digitalWrite(rows[3], 1);
|
||||
digitalWrite(rows[4], 1);
|
||||
digitalWrite(rows[5], 1);
|
||||
digitalWrite(rows[6], 1);
|
||||
delay(2000);
|
||||
*/
|
||||
}
|
||||
|
||||
void loop() {
|
||||
Serial.println("Foo");
|
||||
|
||||
digitalWrite(cols[0], 1);
|
||||
digitalWrite(cols[1], 1);
|
||||
digitalWrite(cols[2], 1);
|
||||
digitalWrite(cols[3], 1);
|
||||
digitalWrite(cols[4], 1);
|
||||
digitalWrite(rows[0], 0);
|
||||
digitalWrite(rows[1], 0);
|
||||
digitalWrite(rows[2], 0);
|
||||
digitalWrite(rows[3], 0);
|
||||
digitalWrite(rows[4], 0);
|
||||
digitalWrite(rows[5], 0);
|
||||
digitalWrite(rows[6], 0);
|
||||
delay(2000);
|
||||
digitalWrite(cols[0], 1);
|
||||
digitalWrite(cols[1], 0);
|
||||
digitalWrite(cols[2], 1);
|
||||
digitalWrite(cols[3], 0);
|
||||
digitalWrite(cols[4], 1);
|
||||
digitalWrite(rows[0], 1);
|
||||
digitalWrite(rows[1], 0);
|
||||
digitalWrite(rows[2], 1);
|
||||
digitalWrite(rows[3], 0);
|
||||
digitalWrite(rows[4], 1);
|
||||
digitalWrite(rows[5], 0);
|
||||
digitalWrite(rows[6], 1);
|
||||
delay(2000);
|
||||
|
||||
}
|
||||
|
|
@ -1,35 +0,0 @@
|
|||
|
||||
#define OUTPUT0 13
|
||||
#define OUTPUT1 12
|
||||
#define OUTPUT2 11
|
||||
|
||||
void setup() {
|
||||
|
||||
//Serial.begin(9600);
|
||||
|
||||
|
||||
pinMode(OUTPUT0, OUTPUT);
|
||||
pinMode(OUTPUT1, OUTPUT);
|
||||
pinMode(OUTPUT2, OUTPUT);
|
||||
|
||||
|
||||
}
|
||||
|
||||
void loop() {
|
||||
digitalWrite(OUTPUT0, LOW);
|
||||
digitalWrite(OUTPUT1, LOW);
|
||||
digitalWrite(OUTPUT2, LOW);
|
||||
delay(100);
|
||||
digitalWrite(OUTPUT0, HIGH);
|
||||
digitalWrite(OUTPUT1, LOW);
|
||||
digitalWrite(OUTPUT2, LOW);
|
||||
delay(100);
|
||||
digitalWrite(OUTPUT0, LOW);
|
||||
digitalWrite(OUTPUT1, HIGH);
|
||||
digitalWrite(OUTPUT2, LOW);
|
||||
delay(100);
|
||||
digitalWrite(OUTPUT0, HIGH);
|
||||
digitalWrite(OUTPUT1, HIGH);
|
||||
digitalWrite(OUTPUT2, LOW);
|
||||
delay(100);
|
||||
}
|
||||
|
|
@ -1,37 +0,0 @@
|
|||
/*
|
||||
* an arduino sketch to interface with a ps/2 keyboard.
|
||||
* Also uses serial protocol to talk back to the host
|
||||
* and report what it finds. Used the ps2 library.
|
||||
*/
|
||||
|
||||
#include <ps2.h>
|
||||
|
||||
/*
|
||||
* Pin 5 is the ps2 data pin, pin 6 is the clock pin
|
||||
* Feel free to use whatever pins are convenient.
|
||||
*/
|
||||
|
||||
PS2 kbd(6, 5);
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(9600);
|
||||
kbd.init_kbd();
|
||||
}
|
||||
|
||||
/*
|
||||
* get a keycode from the kbd and report it back to the
|
||||
* host via the serial line.
|
||||
*/
|
||||
void loop()
|
||||
{
|
||||
unsigned char code;
|
||||
|
||||
for (;;) { /* ever */
|
||||
/* read a keycode */
|
||||
code = kbd.read();
|
||||
/* send the data back up */
|
||||
Serial.println(code, HEX);
|
||||
// delay(20); /* twiddle */
|
||||
}
|
||||
}
|
||||
|
|
@ -1,52 +0,0 @@
|
|||
#include <ps2.h>
|
||||
|
||||
/*
|
||||
* an arduino sketch to interface with a ps/2 mouse.
|
||||
* Also uses serial protocol to talk back to the host
|
||||
* and report what it finds.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Pin 5 is the mouse data pin, pin 6 is the clock pin
|
||||
* Feel free to use whatever pins are convenient.
|
||||
*/
|
||||
PS2 mouse(6, 5);
|
||||
|
||||
/*
|
||||
* initialize the mouse. Reset it, and place it into remote
|
||||
* mode, so we can get the encoder data on demand.
|
||||
*/
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(9600);
|
||||
mouse.init_mouse();
|
||||
}
|
||||
|
||||
/*
|
||||
* get a reading from the mouse and report it back to the
|
||||
* host via the serial line.
|
||||
*/
|
||||
void loop()
|
||||
{
|
||||
char mstat;
|
||||
char mx;
|
||||
char my;
|
||||
|
||||
/* get a reading from the mouse */
|
||||
mouse.write(0xeb); // give me data!
|
||||
mouse.read(); // ignore ack
|
||||
mstat = mouse.read();
|
||||
mx = mouse.read();
|
||||
my = mouse.read();
|
||||
|
||||
/* send the data back up */
|
||||
Serial.print(mstat, BIN);
|
||||
Serial.print("\tX=");
|
||||
Serial.print(mx, DEC);
|
||||
Serial.print("\tY=");
|
||||
Serial.print(my, DEC);
|
||||
Serial.println();
|
||||
delay(20); /* twiddle */
|
||||
}
|
||||
|
|
@ -1,21 +0,0 @@
|
|||
|
||||
|
||||
#include <Wire.h>
|
||||
|
||||
void setup()
|
||||
{
|
||||
Wire.begin(); // join i2c bus (address optional for master)
|
||||
}
|
||||
|
||||
byte x = 0;
|
||||
|
||||
void loop()
|
||||
{
|
||||
Wire.beginTransmission(72); // transmit to device #4
|
||||
Wire.send("x is "); // sends five bytes
|
||||
Wire.send(x); // sends one byte
|
||||
Wire.endTransmission(); // stop transmitting
|
||||
|
||||
x++;
|
||||
delay(500);
|
||||
}
|
||||
|
|
@ -1,88 +0,0 @@
|
|||
//3led fnordlicht//
|
||||
|
||||
int value = 0;
|
||||
int bluepin = 9;
|
||||
int greenpin = 10;
|
||||
int redpin = 11;
|
||||
|
||||
void setup()
|
||||
{
|
||||
pinMode(bluepin, OUTPUT);
|
||||
pinMode(greenpin, OUTPUT);
|
||||
pinMode(redpin,OUTPUT);
|
||||
|
||||
//led test start
|
||||
digitalWrite(bluepin, HIGH);
|
||||
delay(200);
|
||||
digitalWrite(bluepin, LOW);
|
||||
digitalWrite(greenpin, HIGH);
|
||||
delay(200);
|
||||
digitalWrite(greenpin, LOW);
|
||||
digitalWrite(redpin, HIGH);
|
||||
delay(200);
|
||||
digitalWrite(redpin, LOW);
|
||||
|
||||
digitalWrite(bluepin, HIGH);
|
||||
delay(200);
|
||||
digitalWrite(bluepin, LOW);
|
||||
digitalWrite(greenpin, HIGH);
|
||||
delay(200);
|
||||
digitalWrite(greenpin, LOW);
|
||||
digitalWrite(redpin, HIGH);
|
||||
delay(200);
|
||||
digitalWrite(redpin, LOW);
|
||||
|
||||
digitalWrite(bluepin, HIGH);
|
||||
delay(200);
|
||||
digitalWrite(bluepin, LOW);
|
||||
digitalWrite(greenpin, HIGH);
|
||||
delay(200);
|
||||
digitalWrite(greenpin, LOW);
|
||||
digitalWrite(redpin, HIGH);
|
||||
delay(200);
|
||||
digitalWrite(redpin, LOW);
|
||||
delay(5000);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
digitalWrite(bluepin, 255+value);
|
||||
for(value = 4 ; value <= 255; value+=1)
|
||||
{
|
||||
analogWrite(redpin, value);
|
||||
analogWrite(greenpin, value);
|
||||
delay(50);
|
||||
}
|
||||
for(value = 255; value >=4; value-=1)
|
||||
{
|
||||
analogWrite(bluepin, value);
|
||||
analogWrite(greenpin, value);
|
||||
delay(50);
|
||||
}
|
||||
//fading 2
|
||||
for(value = 4 ; value <= 255; value+=1)
|
||||
{
|
||||
analogWrite(bluepin, value);
|
||||
analogWrite(greenpin, value);
|
||||
delay(50);
|
||||
}
|
||||
for(value = 255; value >=4; value-=1)
|
||||
{
|
||||
analogWrite(bluepin, value);
|
||||
analogWrite(redpin, value);
|
||||
delay(50);
|
||||
}
|
||||
//fading 3
|
||||
for(value = 4 ; value <= 255; value+=1)
|
||||
{
|
||||
analogWrite(redpin, value);
|
||||
analogWrite(bluepin, value);
|
||||
delay(50);
|
||||
}
|
||||
for(value = 255; value >=4; value-=1)
|
||||
{
|
||||
analogWrite(redpin, value);
|
||||
analogWrite(greenpin, value);
|
||||
delay(50);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,95 +0,0 @@
|
|||
//164 pins
|
||||
int clearPin = 2; // enablepin
|
||||
int dataPin = 3;
|
||||
int clockPin = 4;
|
||||
|
||||
//165 pins
|
||||
int inclearPin = 11; // enablepin
|
||||
int indataPin = 9;
|
||||
int inclockPin = 10;
|
||||
int inloadPin = 12; // toggling this tells the 165 to read the value into its memory for reading
|
||||
|
||||
int temp = 0;
|
||||
|
||||
void setup() {
|
||||
|
||||
//start serial
|
||||
Serial.begin(9600);
|
||||
|
||||
//164
|
||||
pinMode(clearPin, OUTPUT);
|
||||
digitalWrite(clearPin, 1); // enable output, you could also tie this pin to VCC
|
||||
pinMode(dataPin, OUTPUT);
|
||||
pinMode(clockPin, OUTPUT);
|
||||
|
||||
//165
|
||||
pinMode(inclearPin, OUTPUT);
|
||||
digitalWrite(inclearPin, 0); // enable input, you could also tie this pin to GND
|
||||
pinMode(indataPin, INPUT);
|
||||
pinMode(inclockPin, OUTPUT);
|
||||
pinMode(inloadPin, OUTPUT);
|
||||
|
||||
|
||||
//we want to set the 164's outputs to any combination of 1's and 0's we want
|
||||
//going to set the 164 outputs to 11101101 or on,on,on,off,on,on,off,on if you prefer, where on is 5v and off is grnd
|
||||
//1st bit
|
||||
digitalWrite(clockPin, 0);
|
||||
digitalWrite(dataPin, 1);
|
||||
digitalWrite(clockPin, 1);
|
||||
//2nd bit
|
||||
digitalWrite(clockPin, 0);
|
||||
digitalWrite(dataPin, 1);
|
||||
digitalWrite(clockPin, 1);
|
||||
//3rd bit
|
||||
digitalWrite(clockPin, 0);
|
||||
digitalWrite(dataPin, 1);
|
||||
digitalWrite(clockPin, 1);
|
||||
//4th bit
|
||||
digitalWrite(clockPin, 0);
|
||||
digitalWrite(dataPin, 0);
|
||||
digitalWrite(clockPin, 1);
|
||||
//5th bit
|
||||
digitalWrite(clockPin, 0);
|
||||
digitalWrite(dataPin, 1);
|
||||
digitalWrite(clockPin, 1);
|
||||
//6th bit
|
||||
digitalWrite(clockPin, 0);
|
||||
digitalWrite(dataPin, 1);
|
||||
digitalWrite(clockPin, 1);
|
||||
//7th bit
|
||||
digitalWrite(clockPin, 0);
|
||||
digitalWrite(dataPin, 0);
|
||||
digitalWrite(clockPin, 1);
|
||||
//8th bit
|
||||
digitalWrite(clockPin, 0);
|
||||
digitalWrite(dataPin, 1);
|
||||
digitalWrite(clockPin, 1);
|
||||
|
||||
}
|
||||
|
||||
// now its time to read the values that we outputted back in
|
||||
|
||||
void loop() {
|
||||
|
||||
digitalWrite(inloadPin, 0); // read into register (tells the 165 to take a snapshot of its input pins)
|
||||
digitalWrite(inloadPin, 1); // done reading into register, ready for us to read
|
||||
|
||||
for(int i=0; i<=7; i++){ // read each of the 165's 8 inputs (or its snapshot of it rather)
|
||||
|
||||
// tell the 165 to send the inputs pin state
|
||||
digitalWrite(inclockPin, 0);
|
||||
// read the current output
|
||||
temp = digitalRead(indataPin); // read the state
|
||||
// tell the 165 we are done reading
|
||||
digitalWrite(inclockPin, 1);
|
||||
|
||||
Serial.print (temp);
|
||||
|
||||
}
|
||||
|
||||
Serial.println ("");
|
||||
Serial.println ("--------");
|
||||
|
||||
delay(2000);
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue