├── -temp ├── AnalogInOutSerial └── AnalogInOutSerial.ino ├── Archives ├── Pairtris │ ├── Pairtris.txt │ └── todo.txt └── Scribdbot │ ├── Frubot.txt │ ├── FruitCell.png │ ├── README │ ├── README.txt │ ├── drawgame.css │ ├── game.html │ └── grid.js ├── Ardesperation Xbee.jpg ├── ArduinoSPIpinouts.PNG ├── ArduinoWirelessXbee.jpg ├── Fridgeduino.jpg ├── IRDistance ├── IR-Motor.png └── IRDistance.ino ├── MSP-EXP30G2.jpg ├── Main.txt ├── Pingtool └── Pingtool │ └── Pingtool.ino ├── README.md ├── Xbee-MSP430-duh.jpg ├── buttondial ├── buttondial.ino └── buttondial_ino │ └── buttondial_ino.ino ├── led8 └── led8_ino │ └── led8_ino.ino ├── libraries ├── DHTLib │ ├── dht.cpp │ └── dht.h └── readme.txt ├── motor01 └── motor01.ino ├── motor02 └── motor02.ino ├── motor03 └── motor03.ino ├── motor04 └── motor04.ino ├── nerf01 └── nerf01.ino ├── network_scan01 └── network_scan01.ino ├── rand_num_7seg_led └── rand_num_7seg_led.ino ├── sdcard01 └── sdcard01 │ └── sdcard01.ino ├── wifi01 └── wifi01.ino └── xbeewire.jpg /-temp: -------------------------------------------------------------------------------- 1 | [core] 2 | repositoryformatversion = 0 3 | filemode = false 4 | bare = false 5 | logallrefupdates = true 6 | symlinks = false 7 | ignorecase = true 8 | hideDotFiles = dotGitOnly 9 | [remote "origin"] 10 | -------------------------------------------------------------------------------- /AnalogInOutSerial/AnalogInOutSerial.ino: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | 4 | const int buttonPin = 0; // the number of the pushbutton pin 5 | const int analogInPin = A5; // Analog input pin that the potentiometer is attached to 6 | 7 | int ledPin = 10; // the number of the LED pin 8 | int analogOutPin = 10; // Analog output pin that the LED is attached to 9 | int sensorValue = 0; // value read from the pot 10 | int outputValue = 0; // value output to the PWM (analog out) 11 | int buttonState = 0; 12 | int btnPressed = 1; 13 | int lastButtonState = 0; 14 | int buttonPushCounter = 0; 15 | 16 | LiquidCrystal lcd(1, 6, 5, 4, 3, 2); // LCD input pins 4, 6, 11, 12, 13, 14 17 | 18 | void setup() { 19 | pinMode(ledPin, OUTPUT); 20 | pinMode(buttonPin, INPUT); 21 | 22 | // set up the LCD's number of columns and rows: 23 | lcd.begin(16, 2); 24 | // Print a message to the LCD. 25 | lcd.setCursor(0, 0); 26 | lcd.print("LED:"); 27 | lcd.setCursor(0, 1); 28 | lcd.print("out:"); 29 | lcd.setCursor(8, 0); 30 | lcd.print("tim:"); 31 | lcd.setCursor(8, 1); 32 | lcd.print("cnt:"); 33 | } 34 | 35 | void loop() { 36 | 37 | buttonState = digitalRead(buttonPin); 38 | if (buttonState == HIGH) { 39 | analogOutPin = 10; 40 | sensorValue = analogRead(analogInPin); 41 | outputValue = map(sensorValue, 0, 700, 0, 255); 42 | analogWrite(analogOutPin, outputValue); 43 | // set the cursor to column 0, line 1 44 | // (note: line 1 is the second row, since counting begins with 0): 45 | lcd.setCursor(4, 0); 46 | lcd.print("HIGH"); 47 | lcd.setCursor(4, 1); 48 | lcd.print(" "); 49 | lcd.setCursor(4, 1); 50 | lcd.print(outputValue); 51 | lcd.setCursor(12, 0); 52 | lcd.print(millis()/1000); 53 | lcd.setCursor(12, 1); 54 | lcd.print(buttonPushCounter); 55 | lastButtonState = buttonState; 56 | delay(2); 57 | } else { 58 | analogOutPin = 11; 59 | sensorValue = analogRead(analogInPin); 60 | outputValue = map(sensorValue, 0, 700, 0, 255); 61 | analogWrite(analogOutPin, outputValue); 62 | if (buttonState != lastButtonState) { 63 | buttonPushCounter++; 64 | } 65 | // set the cursor to column 0, line 1 66 | // (note: line 1 is the second row, since counting begins with 0): 67 | lcd.setCursor(4, 0); 68 | lcd.print("LOW "); 69 | lcd.setCursor(4, 1); 70 | lcd.print(" "); 71 | lcd.setCursor(4, 1); 72 | lcd.print(outputValue); 73 | lcd.setCursor(12, 0); 74 | lcd.print(millis()/1000); 75 | lcd.setCursor(12, 1); 76 | lcd.print(buttonPushCounter); 77 | lastButtonState = buttonState; 78 | delay(2); 79 | } 80 | 81 | } 82 | 83 | -------------------------------------------------------------------------------- /Archives/Pairtris/Pairtris.txt: -------------------------------------------------------------------------------- 1 | Tetris multiplayer app 2 | 3 | 3 pieces: 4 | -html5 app 5 | -concurrency 6 | -host from phone webserver 7 | 8 | HTML5 App 9 | -Tetris: https://github.com/daltonridenhour/DOM-Tetris 10 | -Needs to have touch added: http://www.html5rocks.com/en/mobile/touch/ 11 | -Needs to have "concurrent lines" thing built in somehow... 12 | 13 | Concurrency 14 | -Bluetooth 15 | --Android: http://developer.android.com/guide/topics/wireless/bluetooth.html 16 | --iOS: http://www.devx.com/wireless/Article/43502/0/page/1 17 | 18 | 19 | Webapp wrapper 20 | -Phonegap: http://phonegap.com/ 21 | 22 | References: 23 | http://docs.oracle.com/javase/tutorial/networking/datagrams/index.html 24 | http://gafferongames.com/networking-for-game-programmers/ 25 | http://sixrevisions.com/web-development/html5-iphone-app/# 26 | http://www.lostdecadegames.com/how-to-make-a-simple-html5-canvas-game/ 27 | 28 | car: 29 | 175 Hood 30 | 75 Radiator 31 | 175 Bumper 32 | 40 Grille 33 | 120 Radiator support 34 | 35 | $600 -------------------------------------------------------------------------------- /Archives/Pairtris/todo.txt: -------------------------------------------------------------------------------- 1 | To turn goblin game into pairtris 2 | 3 | 1. mechanics 4 | -only drop 1 piece at a time (2nd piece is next game mode) 5 | -make pieces fall automatically 6 | 7 | 8 | 9 | 2. controls 10 | -add in touch support later? 11 | 12 | 13 | 3. graphics 14 | -new bg 15 | -how many colors of squares? 16 | -how to group? 17 | -border (score? next?) 18 | 19 | 20 | -------------------------------------------------------------------------------- /Archives/Scribdbot/Frubot.txt: -------------------------------------------------------------------------------- 1 | My bot is named Frubot 2 | 3 | Normal actions 4 | Frubot makes a list of all fruit on gameboard 5 | -List needs to hold type and location 6 | -List needs a list number? 7 | -List needs to identify if the fruit's in a group? 8 | 9 | -How often to update list? 10 | -Should we update the list and preference separately? 11 | 12 | Frubot orders list by preference 13 | -Preference is adjusted so fruit types with few pieces have higher preference than those with more pieces 14 | -Preference is adjusted by distance to next piece of fruit 15 | -Maybe Frubot will prefer a rare type more than a more common type? 16 | -Frubot will pick up fruit if the fruit is in its path to another type of fruit 17 | -Frubot picks up fruit adjacent to its path 18 | 19 | Actions if Simplebot is near 20 | -Reactions need to be adjusted for large v small boards 21 | 22 | -------------------------------------------------------------------------------- /Archives/Scribdbot/FruitCell.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Gilgamech/Arduino/81e67fb3e10975a872f6095c4068236a550e93b2/Archives/Scribdbot/FruitCell.png -------------------------------------------------------------------------------- /Archives/Scribdbot/README: -------------------------------------------------------------------------------- 1 | Welcome! 2 | 3 | Modify mybot.js to start writing your bot. Opening game.html will allow you to generate random boards, and either watch your bot play or step through one move at a time. Refer to http://scribd.com/job_game/api for available methods. gl/hf! 4 | 5 | Scribd. 6 | 7 | ps: you should be able to ignore everything in assets/, but if you want to disable the opponent bot from playing in game.html, go to assets/simplebot.js and find: 8 | makeMove: function() { 9 | // to disable to opponent, uncomment the next line 10 | // return PASS; 11 | 12 | Uncomment the "return PASS;" and your bot will be free to roam the board alone. 13 | -------------------------------------------------------------------------------- /Archives/Scribdbot/README.txt: -------------------------------------------------------------------------------- 1 | Welcome! 2 | 3 | Modify mybot.js to start writing your bot. Opening game.html will allow you to generate random boards, and either watch your bot play or step through one move at a time. Refer to http://scribd.com/job_game/api for available methods. gl/hf! 4 | 5 | Scribd. 6 | 7 | ps: you should be able to ignore everything in assets/, but if you want to disable the opponent bot from playing in game.html, go to assets/simplebot.js and find: 8 | makeMove: function() { 9 | // to disable to opponent, uncomment the next line 10 | // return PASS; 11 | 12 | Uncomment the "return PASS;" and your bot will be free to roam the board alone. -------------------------------------------------------------------------------- /Archives/Scribdbot/drawgame.css: -------------------------------------------------------------------------------- 1 | .button { 2 | border-top: 1px solid #96d1f8; 3 | background: #77a7c7; 4 | background: -webkit-gradient(linear, left top, left bottom, from(#254459), to(#77a7c7)); 5 | background: -webkit-linear-gradient(top, #254459, #77a7c7); 6 | background: -moz-linear-gradient(top, #254459, #77a7c7); 7 | background: -ms-linear-gradient(top, #254459, #77a7c7); 8 | background: -o-linear-gradient(top, #254459, #77a7c7); 9 | padding: 0px 14px 0px 14px; 10 | margin: 1px; 11 | -webkit-border-radius: 3px; 12 | -moz-border-radius: 3px; 13 | border-radius: 3px; 14 | text-shadow: rgba(0,0,0,.4) 0 1px 0; 15 | color: white; 16 | font-size: 16px; 17 | font-family: Helvetica, Arial, Sans-Serif; 18 | text-decoration: none; 19 | vertical-align: bottom; 20 | } 21 | .button:hover { 22 | border-top-color: #1e2757; 23 | background: #1e2757; 24 | color: #ffffff; 25 | cursor: pointer; 26 | } 27 | .button:active { 28 | border-top-color: #1b435e; 29 | background: #1b435e; 30 | } 31 | canvas { 32 | position:absolute; 33 | left:0px; 34 | top:0px; 35 | } 36 | -------------------------------------------------------------------------------- /Archives/Scribdbot/game.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | new 16 | reset 17 | pause 18 | play 19 | forward 20 |
21 | 22 | 23 | -------------------------------------------------------------------------------- /Archives/Scribdbot/grid.js: -------------------------------------------------------------------------------- 1 | var Grid = { 2 | draw: function() { 3 | var canvas = document.getElementById('grid'); 4 | var ctx = canvas.getContext('2d'); 5 | document.getElementById('grid').width = Board.numberOfItemTypes * 50 + WIDTH * 50; 6 | document.getElementById('grid').height = HEIGHT * 50; 7 | var img = new Image(); 8 | img.onload = function() { 9 | for (var i=0; i 6 | #include 7 | 8 | // set up variables using the SD utility library functions: 9 | Sd2Card card; 10 | SdVolume volume; 11 | SdFile root; 12 | 13 | const int pingPin = 8; 14 | // change this to match your SD shield or module. Arduino Ethernet shield: pin 4 15 | const int chipSelect = 4; 16 | LiquidCrystal lcd(1, 6, 5, 0, 3, 2); // LCD input pins 4, 6, 11, 12, 13, 14 17 | 18 | void setup() { 19 | 20 | lcd.begin(16, 2); 21 | // Print a message to the LCD. 22 | lcd.setCursor(0, 0); 23 | lcd.print("in cm microsec"); 24 | 25 | // On the Ethernet Shield, CS is pin 4. It's set as an output by default. 26 | // Note that even if it's not used as the CS pin, the hardware SS pin 27 | // (10 on most Arduino boards, 53 on the Mega) must be left as an output 28 | // or the SD library functions will not work. 29 | pinMode(10, OUTPUT); // change this to 53 on a mega 30 | 31 | 32 | // initialize serial communication: 33 | // Serial.begin(9600); 34 | } 35 | 36 | void loop() 37 | { 38 | // establish variables for duration of the ping, 39 | // and the distance result in inches and centimeters: 40 | long duration, inches, cm; 41 | 42 | // The PING))) is triggered by a HIGH pulse of 2 or more microseconds. 43 | // Give a short LOW pulse beforehand to ensure a clean HIGH pulse: 44 | pinMode(pingPin, OUTPUT); 45 | digitalWrite(pingPin, LOW); 46 | delayMicroseconds(2); 47 | digitalWrite(pingPin, HIGH); 48 | delayMicroseconds(5); 49 | digitalWrite(pingPin, LOW); 50 | 51 | // The same pin is used to read the signal from the PING))): a HIGH 52 | // pulse whose duration is the time (in microseconds) from the sending 53 | // of the ping to the reception of its echo off of an object. 54 | pinMode(pingPin, INPUT); 55 | duration = pulseIn(pingPin, HIGH); 56 | 57 | // convert the time into a distance 58 | inches = microsecondsToInches(duration); 59 | cm = microsecondsToCentimeters(duration); 60 | 61 | lcd.setCursor(0, 1); 62 | lcd.print(" "); 63 | lcd.setCursor(0, 1); 64 | lcd.print(inches); 65 | lcd.setCursor(4, 1); 66 | lcd.print(cm); 67 | lcd.setCursor(8, 1); 68 | lcd.print(duration); 69 | 70 | delay(10); 71 | } 72 | 73 | long microsecondsToInches(long microseconds) 74 | { 75 | // According to Parallax's datasheet for the PING))), there are 76 | // 73.746 microseconds per inch (i.e. sound travels at 1130 feet per 77 | // second). This gives the distance travelled by the ping, outbound 78 | // and return, so we divide by 2 to get the distance of the obstacle. 79 | // See: http://www.parallax.com/dl/docs/prod/acc/28015-PING-v1.3.pdf 80 | return microseconds / 74 / 2; 81 | } 82 | 83 | long microsecondsToCentimeters(long microseconds) 84 | { 85 | // The speed of sound is 340 m/s or 29 microseconds per centimeter. 86 | // The ping travels out and back, so to find the distance of the 87 | // object we take half of the distance travelled. 88 | return microseconds / 29 / 2; 89 | } 90 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Test test 2 | -------------------------------------------------------------------------------- /Xbee-MSP430-duh.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Gilgamech/Arduino/81e67fb3e10975a872f6095c4068236a550e93b2/Xbee-MSP430-duh.jpg -------------------------------------------------------------------------------- /buttondial/buttondial.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Button 3 | 4 | Turns on and off a light emitting diode(LED) connected to digital 5 | pin 13, when pressing a pushbutton attached to pin 2. 6 | 7 | 8 | The circuit: 9 | * LED attached from pin 13 to ground 10 | * pushbutton attached to pin 2 from +5V 11 | * 10K resistor attached to pin 2 from ground 12 | 13 | * Note: on most Arduinos there is already an LED on the board 14 | attached to pin 13. 15 | 16 | 17 | created 2005 18 | by DojoDave 19 | modified 30 Aug 2011 20 | by Tom Igoe 21 | 22 | This example code is in the public domain. 23 | 24 | http://www.arduino.cc/en/Tutorial/Button 25 | */ 26 | 27 | // constants won't change. They're used here to 28 | // set pin numbers: 29 | const int analogInPin = A0; // Analog input pin that the potentiometer is attached to 30 | const int buttonPin = 2; // the number of the pushbutton pin 31 | 32 | // variables will change: 33 | int sensorValue = 0; // value read from the pot 34 | int outputValue = 0; // value output to the PWM (analog out) 35 | int buttonState = 0; // variable for reading the pushbutton status 36 | int analogOutPin = 7; 37 | 38 | void setup() { 39 | Serial.begin(9600); 40 | // initialize the LED pin as an output: 41 | // pinMode(ledRED, OUTPUT); 42 | // pinMode(ledBLUE, OUTPUT); 43 | // initialize the pushbutton pin as an input: 44 | pinMode(buttonPin, INPUT); 45 | } 46 | 47 | void loop(){ 48 | // read the analog in value: 49 | //sensorValue = analogRead(analogInPin); 50 | // read the state of the pushbutton value: 51 | buttonState = digitalRead(buttonPin); 52 | sensorValue = analogRead(analogInPin); 53 | 54 | if (buttonState == LOW) { 55 | analogOutPin = 8; 56 | outputValue = map(sensorValue, 0, 1023, 0, 255); 57 | analogWrite(analogOutPin, outputValue); 58 | // print the results to the serial monitor: 59 | Serial.print("BTN=" ); 60 | Serial.print(buttonState); 61 | Serial.print("\t sensor=" ); 62 | Serial.print(sensorValue); 63 | Serial.print("\t output="); 64 | Serial.println(outputValue); 65 | Serial.print("\t LED="); 66 | Serial.println(analogOutPin); 67 | // outputValue = 0 ; 68 | delay(2); 69 | } else { 70 | analogOutPin = 6; 71 | outputValue = map(sensorValue, 0, 1023, 0, 255); 72 | analogWrite(analogOutPin, outputValue); 73 | // print the results to the serial monitor: 74 | Serial.print("BTN=" ); 75 | Serial.print(buttonState); 76 | Serial.print("\t sensor=" ); 77 | Serial.print(sensorValue); 78 | Serial.print("\t output="); 79 | Serial.println(outputValue); 80 | Serial.print("\t LED="); 81 | Serial.println(analogOutPin); 82 | delay(2); 83 | } 84 | 85 | // wait 2 milliseconds before the next loop 86 | // for the analog-to-digital converter to settle 87 | // after the last reading: 88 | 89 | } 90 | -------------------------------------------------------------------------------- /buttondial/buttondial_ino/buttondial_ino.ino: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | 4 | const int buttonPin = 12; // the number of the pushbutton pin 5 | const int ledPin = 10; // the number of the LED pin 6 | const int analogInPin = A5; // Analog input pin that the potentiometer is attached to 7 | 8 | int analogOutPin = 10; // Analog output pin that the LED is attached to 9 | int sensorValue = 0; // value read from the pot 10 | int outputValue = 0; // value output to the PWM (analog out) 11 | int buttonState = 0; 12 | int buttonPress = 0; 13 | int lastButtonState = 0; 14 | 15 | LiquidCrystal lcd(1, 6, 5, 4, 3, 2); 16 | 17 | void setup() { 18 | //Serial.begin(9600); 19 | pinMode(ledPin, OUTPUT); 20 | pinMode(buttonPin, INPUT); 21 | // set up the LCD's number of columns and rows: 22 | lcd.begin(16, 2); 23 | // Print a message to the LCD. 24 | lcd.print("PIN "); 25 | lcd.setCursor(0, 1); 26 | lcd.print("Out "); 27 | } 28 | 29 | void loop() { 30 | 31 | buttonState = digitalRead(buttonPin); 32 | if (buttonState == HIGH) { 33 | analogOutPin = 10; 34 | } else { 35 | analogOutPin = 11; 36 | if (buttonState != lastButtonState) { 37 | buttonPress++; 38 | } 39 | } 40 | sensorValue = analogRead(analogInPin); 41 | outputValue = map(sensorValue, 0, 700, 0, 255); 42 | analogWrite(analogOutPin, outputValue); 43 | 44 | // set the cursor to column 0, line 1 45 | // (note: line 1 is the second row, since counting begins with 0): 46 | lcd.setCursor(4, 0); 47 | lcd.print(" "); 48 | lcd.setCursor(4, 0); 49 | lcd.print(analogOutPin); 50 | lcd.setCursor(4, 1); 51 | lcd.print(" "); 52 | lcd.setCursor(4, 1); 53 | lcd.print(outputValue); 54 | // print the number of seconds since reset: 55 | lcd.setCursor(13, 0); 56 | lcd.print(millis()/1000); 57 | lcd.setCursor(13, 1); 58 | lcd.print(buttonPress); 59 | lastButtonState = buttonState; 60 | 61 | delay(2); 62 | } 63 | -------------------------------------------------------------------------------- /led8/led8_ino/led8_ino.ino: -------------------------------------------------------------------------------- 1 | #include 2 | int ledPin = 8; // the 7-seg output pin. 3 | int buttonState = 0; 4 | int lastButtonState = 0; 5 | int buttonPushCounter = 0; 6 | 7 | LiquidCrystal lcd(1, 6, 5, 4, 3, 2); // LCD input pins 4, 6, 11, 12, 13, 14 8 | 9 | void setup() { 10 | pinMode(7, OUTPUT); 11 | pinMode(8, OUTPUT); 12 | pinMode(9, OUTPUT); 13 | pinMode(10, OUTPUT); 14 | pinMode(11, OUTPUT); 15 | pinMode(12, OUTPUT); 16 | pinMode(13, OUTPUT); 17 | pinMode(0, INPUT); 18 | 19 | // set up the LCD's number of columns and rows: 20 | // lcd.begin(16, 2); 21 | // // Print a message to the LCD. 22 | // lcd.setCursor(0, 0); 23 | // lcd.print("LED:"); 24 | // lcd.setCursor(0, 1); 25 | // lcd.print("out:"); 26 | // lcd.setCursor(8, 0); 27 | // lcd.print("tim:"); 28 | // lcd.setCursor(8, 1); 29 | // lcd.print("cnt:"); 30 | } 31 | 32 | void loop() { 33 | buttonState = digitalRead(0); 34 | if (buttonState == LOW) { 35 | // set the cursor to column 0, line 1 36 | // (note: line 1 is the second row, since counting begins with 0): 37 | // lcd.setCursor(4, 0); 38 | // lcd.print("HIGH"); 39 | // lcd.setCursor(12, 0); 40 | // lcd.print(500-millis()/1000); 41 | // lcd.setCursor(12, 1); 42 | // lcd.print(buttonPushCounter); 43 | // lastButtonState = buttonState; 44 | // delay(2); 45 | } else { 46 | //if (buttonState != lastButtonState) { 47 | buttonPushCounter = random(0,10); 48 | } 49 | if (buttonPushCounter == 1){ 50 | digitalWrite(1, LOW); // Top Bar 51 | digitalWrite(2, LOW); // Up Left 52 | digitalWrite(3, HIGH); // Up Right 53 | digitalWrite(4, LOW); // Middle bar 54 | digitalWrite(5, HIGH); // Bottom Right 55 | digitalWrite(6, LOW); // Bottom Left 56 | digitalWrite(7, LOW); // Bottom bar 57 | } 58 | if (buttonPushCounter == 2){ 59 | digitalWrite(1, HIGH); // Top Bar 60 | digitalWrite(2, LOW); // Up Left 61 | digitalWrite(3, HIGH); // Up Right 62 | digitalWrite(4, HIGH); // Middle bar 63 | digitalWrite(5, LOW); // Bottom Right 64 | digitalWrite(6, HIGH); // Bottom Left 65 | digitalWrite(7, HIGH); // Bottom bar 66 | } 67 | if (buttonPushCounter == 3){ 68 | digitalWrite(1, HIGH); // Top Bar 69 | digitalWrite(2, LOW); // Up Left 70 | digitalWrite(3, HIGH); // Up Right 71 | digitalWrite(4, HIGH); // Middle bar 72 | digitalWrite(5, HIGH); // Bottom Right 73 | digitalWrite(6, LOW); // Bottom Left 74 | digitalWrite(7, HIGH); // Bottom bar 75 | } 76 | if (buttonPushCounter == 4){ 77 | digitalWrite(1, LOW); // Top Bar 78 | digitalWrite(2, HIGH); // Up Left 79 | digitalWrite(3, HIGH); // Up Right 80 | digitalWrite(4, HIGH); // Middle bar 81 | digitalWrite(5, HIGH); // Bottom Right 82 | digitalWrite(6, LOW); // Bottom Left 83 | digitalWrite(7, LOW); // Bottom bar 84 | } 85 | if (buttonPushCounter == 5){ 86 | digitalWrite(1, HIGH); // Top Bar 87 | digitalWrite(2, HIGH); // Up Left 88 | digitalWrite(3, LOW); // Up Right 89 | digitalWrite(4, HIGH); // Middle bar 90 | digitalWrite(5, HIGH); // Bottom Right 91 | digitalWrite(6, LOW); // Bottom Left 92 | digitalWrite(7, HIGH); // Bottom bar 93 | } 94 | if (buttonPushCounter == 6){ 95 | digitalWrite(1, HIGH); // Top Bar 96 | digitalWrite(2, HIGH); // Up Left 97 | digitalWrite(3, LOW); // Up Right 98 | digitalWrite(4, HIGH); // Middle bar 99 | digitalWrite(5, HIGH); // Bottom Right 100 | digitalWrite(6, HIGH); // Bottom Left 101 | digitalWrite(7, HIGH); // Bottom bar 102 | } 103 | if (buttonPushCounter == 7){ 104 | digitalWrite(1, HIGH); // Top Bar 105 | digitalWrite(2, LOW); // Up Left 106 | digitalWrite(3, HIGH); // Up Right 107 | digitalWrite(4, LOW); // Middle bar 108 | digitalWrite(5, HIGH); // Bottom Right 109 | digitalWrite(6, LOW); // Bottom Left 110 | digitalWrite(7, LOW); // Bottom bar 111 | } 112 | if (buttonPushCounter == 8){ 113 | digitalWrite(1, HIGH); // Top Bar 114 | digitalWrite(2, HIGH); // Up Left 115 | digitalWrite(3, HIGH); // Up Right 116 | digitalWrite(4, HIGH); // Middle bar 117 | digitalWrite(5, HIGH); // Bottom Right 118 | digitalWrite(6, HIGH); // Bottom Left 119 | digitalWrite(7, HIGH); // Bottom bar 120 | } 121 | if (buttonPushCounter == 9){ 122 | digitalWrite(1, HIGH); // Top Bar 123 | digitalWrite(2, HIGH); // Up Left 124 | digitalWrite(3, HIGH); // Up Right 125 | digitalWrite(4, HIGH); // Middle bar 126 | digitalWrite(5, HIGH); // Bottom Right 127 | digitalWrite(6, LOW); // Bottom Left 128 | digitalWrite(7, HIGH); // Bottom bar 129 | } 130 | if (buttonPushCounter == 10){ 131 | buttonPushCounter = 0; 132 | digitalWrite(1, HIGH); // Top Bar 133 | digitalWrite(2, HIGH); // Up Left 134 | digitalWrite(3, HIGH); // Up Right 135 | digitalWrite(4, LOW); // Middle bar 136 | digitalWrite(5, HIGH); // Bottom Right 137 | digitalWrite(6, HIGH); // Bottom Left 138 | digitalWrite(7, HIGH); // Bottom bar 139 | } 140 | 141 | 142 | // set the cursor to column 0, line 1 143 | // (note: line 1 is the second row, since counting begins with 0): 144 | // lcd.setCursor(4, 0); 145 | // lcd.print("LOW "); 146 | // lcd.setCursor(12, 0); 147 | // lcd.print(500-millis()/1000); 148 | // lcd.setCursor(12, 1); 149 | // lcd.print(buttonPushCounter); 150 | // lastButtonState = buttonState; 151 | delay(50); 152 | } 153 | 154 | 155 | 156 | //} 157 | 158 | -------------------------------------------------------------------------------- /libraries/DHTLib/dht.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // FILE: dht.cpp 3 | // AUTHOR: Rob Tillaart 4 | // VERSION: 0.1.14 5 | // PURPOSE: DHT Temperature & Humidity Sensor library for Arduino 6 | // URL: http://arduino.cc/playground/Main/DHTLib 7 | // 8 | // HISTORY: 9 | // 0.1.14 replace digital read with faster (~3x) code => more robust low MHz machines. 10 | // 0.1.13 fix negative temperature 11 | // 0.1.12 support DHT33 and DHT44 initial version 12 | // 0.1.11 renamed DHTLIB_TIMEOUT 13 | // 0.1.10 optimized faster WAKEUP + TIMEOUT 14 | // 0.1.09 optimize size: timeout check + use of mask 15 | // 0.1.08 added formula for timeout based upon clockspeed 16 | // 0.1.07 added support for DHT21 17 | // 0.1.06 minimize footprint (2012-12-27) 18 | // 0.1.05 fixed negative temperature bug (thanks to Roseman) 19 | // 0.1.04 improved readability of code using DHTLIB_OK in code 20 | // 0.1.03 added error values for temp and humidity when read failed 21 | // 0.1.02 added error codes 22 | // 0.1.01 added support for Arduino 1.0, fixed typos (31/12/2011) 23 | // 0.1.00 by Rob Tillaart (01/04/2011) 24 | // 25 | // inspired by DHT11 library 26 | // 27 | // Released to the public domain 28 | // 29 | 30 | #include "dht.h" 31 | 32 | ///////////////////////////////////////////////////// 33 | // 34 | // PUBLIC 35 | // 36 | 37 | // return values: 38 | // DHTLIB_OK 39 | // DHTLIB_ERROR_CHECKSUM 40 | // DHTLIB_ERROR_TIMEOUT 41 | int dht::read11(uint8_t pin) 42 | { 43 | // READ VALUES 44 | int rv = _readSensor(pin, DHTLIB_DHT11_WAKEUP); 45 | if (rv != DHTLIB_OK) 46 | { 47 | humidity = DHTLIB_INVALID_VALUE; // invalid value, or is NaN prefered? 48 | temperature = DHTLIB_INVALID_VALUE; // invalid value 49 | return rv; 50 | } 51 | 52 | // CONVERT AND STORE 53 | humidity = bits[0]; // bits[1] == 0; 54 | temperature = bits[2]; // bits[3] == 0; 55 | 56 | // TEST CHECKSUM 57 | // bits[1] && bits[3] both 0 58 | uint8_t sum = bits[0] + bits[2]; 59 | if (bits[4] != sum) return DHTLIB_ERROR_CHECKSUM; 60 | 61 | return DHTLIB_OK; 62 | } 63 | 64 | 65 | // return values: 66 | // DHTLIB_OK 67 | // DHTLIB_ERROR_CHECKSUM 68 | // DHTLIB_ERROR_TIMEOUT 69 | int dht::read(uint8_t pin) 70 | { 71 | // READ VALUES 72 | int rv = _readSensor(pin, DHTLIB_DHT_WAKEUP); 73 | if (rv != DHTLIB_OK) 74 | { 75 | humidity = DHTLIB_INVALID_VALUE; // invalid value, or is NaN prefered? 76 | temperature = DHTLIB_INVALID_VALUE; // invalid value 77 | return rv; // propagate error value 78 | } 79 | 80 | // CONVERT AND STORE 81 | humidity = word(bits[0], bits[1]) * 0.1; 82 | temperature = word(bits[2] & 0x7F, bits[3]) * 0.1; 83 | if (bits[2] & 0x80) // negative temperature 84 | { 85 | temperature = -temperature; 86 | } 87 | 88 | // TEST CHECKSUM 89 | uint8_t sum = bits[0] + bits[1] + bits[2] + bits[3]; 90 | if (bits[4] != sum) 91 | { 92 | return DHTLIB_ERROR_CHECKSUM; 93 | } 94 | return DHTLIB_OK; 95 | } 96 | 97 | ///////////////////////////////////////////////////// 98 | // 99 | // PRIVATE 100 | // 101 | 102 | // return values: 103 | // DHTLIB_OK 104 | // DHTLIB_ERROR_TIMEOUT 105 | int dht::_readSensor(uint8_t pin, uint8_t wakeupDelay) 106 | { 107 | // INIT BUFFERVAR TO RECEIVE DATA 108 | uint8_t mask = 128; 109 | uint8_t idx = 0; 110 | 111 | // replace digitalRead() with Direct Port Reads. 112 | // reduces footprint ~100 bytes => portability issue? 113 | // direct port read is about 3x faster 114 | uint8_t bit = digitalPinToBitMask(pin); 115 | uint8_t port = digitalPinToPort(pin); 116 | volatile uint8_t *PIR = portInputRegister(port); 117 | 118 | // EMPTY BUFFER 119 | for (uint8_t i = 0; i < 5; i++) bits[i] = 0; 120 | 121 | // REQUEST SAMPLE 122 | pinMode(pin, OUTPUT); 123 | digitalWrite(pin, LOW); // T-be 124 | delay(wakeupDelay); 125 | digitalWrite(pin, HIGH); // T-go 126 | delayMicroseconds(40); 127 | pinMode(pin, INPUT); 128 | 129 | // GET ACKNOWLEDGE or TIMEOUT 130 | uint16_t loopCntLOW = DHTLIB_TIMEOUT; 131 | while ((*PIR & bit) == LOW ) // T-rel 132 | { 133 | if (--loopCntLOW == 0) return DHTLIB_ERROR_TIMEOUT; 134 | } 135 | 136 | uint16_t loopCntHIGH = DHTLIB_TIMEOUT; 137 | while ((*PIR & bit) != LOW ) // T-reh 138 | { 139 | if (--loopCntHIGH == 0) return DHTLIB_ERROR_TIMEOUT; 140 | } 141 | 142 | // READ THE OUTPUT - 40 BITS => 5 BYTES 143 | for (uint8_t i = 40; i != 0; i--) 144 | { 145 | loopCntLOW = DHTLIB_TIMEOUT; 146 | while ((*PIR & bit) == LOW ) 147 | { 148 | if (--loopCntLOW == 0) return DHTLIB_ERROR_TIMEOUT; 149 | } 150 | 151 | uint32_t t = micros(); 152 | 153 | loopCntHIGH = DHTLIB_TIMEOUT; 154 | while ((*PIR & bit) != LOW ) 155 | { 156 | if (--loopCntHIGH == 0) return DHTLIB_ERROR_TIMEOUT; 157 | } 158 | 159 | if ((micros() - t) > 40) 160 | { 161 | bits[idx] |= mask; 162 | } 163 | mask >>= 1; 164 | if (mask == 0) // next byte? 165 | { 166 | mask = 128; 167 | idx++; 168 | } 169 | } 170 | pinMode(pin, OUTPUT); 171 | digitalWrite(pin, HIGH); 172 | 173 | return DHTLIB_OK; 174 | } 175 | // 176 | // END OF FILE 177 | // -------------------------------------------------------------------------------- /libraries/DHTLib/dht.h: -------------------------------------------------------------------------------- 1 | // 2 | // FILE: dht.h 3 | // AUTHOR: Rob Tillaart 4 | // VERSION: 0.1.14 5 | // PURPOSE: DHT Temperature & Humidity Sensor library for Arduino 6 | // URL: http://arduino.cc/playground/Main/DHTLib 7 | // 8 | // HISTORY: 9 | // see dht.cpp file 10 | // 11 | 12 | #ifndef dht_h 13 | #define dht_h 14 | 15 | #if ARDUINO < 100 16 | #include 17 | #else 18 | #include 19 | #endif 20 | 21 | #define DHT_LIB_VERSION "0.1.14" 22 | 23 | #define DHTLIB_OK 0 24 | #define DHTLIB_ERROR_CHECKSUM -1 25 | #define DHTLIB_ERROR_TIMEOUT -2 26 | #define DHTLIB_INVALID_VALUE -999 27 | 28 | #define DHTLIB_DHT11_WAKEUP 18 29 | #define DHTLIB_DHT_WAKEUP 1 30 | 31 | // max timeout is 100 usec. 32 | // For a 16 Mhz proc 100 usec is 1600 clock cycles 33 | // loops using DHTLIB_TIMEOUT use at least 4 clock cycli 34 | // so 100 us takes max 400 loops 35 | // so by dividing F_CPU by 40000 we "fail" as fast as possible 36 | #define DHTLIB_TIMEOUT (F_CPU/40000) 37 | 38 | class dht 39 | { 40 | public: 41 | // return values: 42 | // DHTLIB_OK 43 | // DHTLIB_ERROR_CHECKSUM 44 | // DHTLIB_ERROR_TIMEOUT 45 | int read11(uint8_t pin); 46 | int read(uint8_t pin); 47 | 48 | inline int read21(uint8_t pin) { return read(pin); }; 49 | inline int read22(uint8_t pin) { return read(pin); }; 50 | inline int read33(uint8_t pin) { return read(pin); }; 51 | inline int read44(uint8_t pin) { return read(pin); }; 52 | 53 | double humidity; 54 | double temperature; 55 | 56 | private: 57 | uint8_t bits[5]; // buffer to receive data 58 | int _readSensor(uint8_t pin, uint8_t wakeupDelay); 59 | }; 60 | #endif 61 | // 62 | // END OF FILE 63 | // -------------------------------------------------------------------------------- /libraries/readme.txt: -------------------------------------------------------------------------------- 1 | For information on installing libraries, see: http://www.arduino.cc/en/Guide/Libraries 2 | -------------------------------------------------------------------------------- /motor01/motor01.ino: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | const int pingPin = 7; 4 | //const int buttonPin = 7; // the number of the pushbutton pin 5 | const int analogInPin = A5; // Analog input pin that the potentiometer is attached to 6 | 7 | //int ledPin = 10; // the number of the LED pin 8 | int analogOutPin = 10; // Analog output pin that the LED is attached to 9 | int sensorValue = 0; // value read from the pot 10 | int outputValue = 0; // value output to the PWM (analog out) 11 | int buttonState = 0; 12 | int btnPressed = 1; 13 | int lastButtonState = 0; 14 | int buttonPushCounter = 0; 15 | 16 | LiquidCrystal lcd(0, 6, 1, 2, 4, 5); // LCD input pins 4, 6, 11, 12, 13, 14 17 | 18 | void setup() { 19 | 20 | lcd.begin(16, 2); 21 | // Print a message to the LCD. 22 | lcd.setCursor(0, 0); 23 | lcd.print("inch out microsec"); 24 | 25 | // On the Ethernet Shield, CS is pin 4. It's set as an output by default. 26 | // Note that even if it's not used as the CS pin, the hardware SS pin 27 | // (10 on most Arduino boards, 53 on the Mega) must be left as an output 28 | // or the SD library functions will not work. 29 | pinMode(10, OUTPUT); // change this to 53 on a mega 30 | 31 | } 32 | 33 | void loop() 34 | { 35 | // establish variables for duration of the ping, 36 | // and the distance result in inches and centimeters: 37 | long duration, inches; 38 | 39 | // The PING))) is triggered by a HIGH pulse of 2 or more microseconds. 40 | // Give a short LOW pulse beforehand to ensure a clean HIGH pulse: 41 | pinMode(pingPin, OUTPUT); 42 | digitalWrite(pingPin, LOW); 43 | delayMicroseconds(2); 44 | digitalWrite(pingPin, HIGH); 45 | delayMicroseconds(5); 46 | digitalWrite(pingPin, LOW); 47 | 48 | // The same pin is used to read the signal from the PING))): a HIGH 49 | // pulse whose duration is the time (in microseconds) from the sending 50 | // of the ping to the reception of its echo off of an object. 51 | pinMode(pingPin, INPUT); 52 | duration = pulseIn(pingPin, HIGH); 53 | 54 | // convert the time into a distance 55 | inches = microsecondsToInches(duration); 56 | 57 | 58 | lcd.setCursor(0, 1); 59 | lcd.print(" "); 60 | lcd.setCursor(0, 1); 61 | lcd.print(inches); 62 | lcd.setCursor(4, 1); 63 | lcd.print(out); 64 | lcd.setCursor(8, 1); 65 | lcd.print(duration); 66 | 67 | delay(10); 68 | } 69 | 70 | long microsecondsToInches(long microseconds) 71 | { 72 | // According to Parallax's datasheet for the PING))), there are 73 | // 73.746 microseconds per inch (i.e. sound travels at 1130 feet per 74 | // second). This gives the distance travelled by the ping, outbound 75 | // and return, so we divide by 2 to get the distance of the obstacle. 76 | // See: http://www.parallax.com/dl/docs/prod/acc/28015-PING-v1.3.pdf 77 | return microseconds / 74 / 2; 78 | } 79 | -------------------------------------------------------------------------------- /motor02/motor02.ino: -------------------------------------------------------------------------------- 1 | const int motorApwm = 3; // Motor A output pin (hardwired on motor shield) 2 | const int pingPin = 7; // pin used by the PING sensor 3 | const int motorBbrk = 8; // Motor B brake pin (hardwired on motor shield) 4 | const int motorAbrk = 9; // Motor A brake pin (hardwired on motor shield) 5 | const int motorBpwm = 11; // Motor B output pin (hardwired on motor shield) 6 | const int motorAdir = 12; // Motor A direction pin (hardwired on motor shield) 7 | const int motorBdir = 13; // Motor B direction pin (hardwired on motor shield) 8 | const int motorAsns = A0; // Motor A sensor pin (hardwired on motor shield) 9 | const int motorBsns = A1; // Motor B sensor pin (hardwired on motor shield) 10 | 11 | int brakeAHigh = LOW; // turn off the parking brake 12 | int pwmAspeed = 0; // set motor speed to 0/255 13 | int dirALowForward = LOW; // Which direction the motor should spin 14 | //LOW = forward, HIGH = reverse 15 | int pingDelay = 100; // how long the processor should idle before continuing, 16 | // needed for ultrasonic ping to work 17 | 18 | int brakeBHigh = LOW; // turn off the steering lock 19 | int pwmBturn = 0; // set steering motor speed to 0 20 | int dirBLowLeft = LOW; // Which direction the motor should spin 21 | //LOW = left?, HIGH = right? 22 | 23 | long lastCm = 14; // Used for speedometer 24 | long carSpeed = 0; // Used for speedometer 25 | 26 | 27 | void setup() { 28 | //Set up the motors for the correct outputs 29 | pinMode(motorAdir, OUTPUT); 30 | pinMode(motorApwm, OUTPUT); 31 | pinMode(motorAbrk, OUTPUT); 32 | pinMode(motorAsns, INPUT); 33 | pinMode(motorBdir, OUTPUT); 34 | pinMode(motorBpwm, OUTPUT); 35 | pinMode(motorBbrk, OUTPUT); 36 | pinMode(motorBsns, INPUT); 37 | // pinMode(buttonPin, INPUT); 38 | 39 | Serial.begin(9600); // To see the values on the PC 40 | } 41 | 42 | void loop() { 43 | long duration, inches, cm; // These 3 variables are used for the 44 | // Distance sensor's math functions below 45 | 46 | // copied from ultrasonic_range 47 | pinMode(pingPin, OUTPUT); // Set the Ping pin to Send 48 | digitalWrite(pingPin, LOW); // Clear the line to the sensor 49 | delayMicroseconds(2); // wait 0.002 seconds 50 | digitalWrite(pingPin, HIGH); // send the ping 51 | delayMicroseconds(5); // wait 0.005 seconds 52 | digitalWrite(pingPin, LOW); // Clear the line to the sensor 53 | // We sent that ping 0.007 seconds ago 54 | pinMode(pingPin, INPUT); // Set the Ping pin to Receive 55 | duration = pulseIn(pingPin, HIGH); // set the variable named Duration to 56 | // be the number of microseconds until the 57 | // ultrasonic ping comes back 58 | 59 | inches = microsecondsToInches(duration); // Calls the function that converts microseconds to inches 60 | cm = microsecondsToCentimeters(duration);// Calls the function that converts microseconds to centimeters 61 | carSpeed = lastCm - cm; //Speedometer. Sets carSpeed to be the previous distance minus the current distance to the wall. 62 | lastCm = cm; // Replaces the previous distance to wall with current distance to wall. 63 | 64 | // Depending on the distance and car speed, speed up or slow down 65 | if (cm<30) { // if we're closer than 30cm 66 | if (carSpeed<3){ // if speed is less than 3 67 | dirALowForward = HIGH; // Direction: reverse 68 | brakeAHigh = LOW; // Brake: off 69 | if (pwmAspeed < 128) { // if PWM output is less than 128 (about 50%) 70 | pwmAspeed += 5; // increase PWM output by 5 (about 2%) 71 | } 72 | }else if (carSpeed>3){ // if speed is more than 20 73 | dirALowForward = HIGH; // Direction: reverse 74 | brakeAHigh = HIGH; // Brakes on 75 | if (pwmAspeed < 128) { //if PWM output is more than 128 (about 50%) 76 | pwmAspeed += 5; // increase PWM output by 5 (about 2%) 77 | } 78 | } 79 | } else if (cm<60){ // at less than 1 meter 80 | dirALowForward = LOW; // Direction: forward 81 | brakeAHigh = LOW; // Brake: off 82 | if (carSpeed<3){ // if carspeed is less than 20 83 | if (pwmAspeed < 25) { // if PWM is less than 245 (about 96%) 84 | pwmAspeed -= 20; // increase PWM by 20 (about 7.8%) 85 | } 86 | }else if (carSpeed>3){ // if carspeed is more than 20 (about 7.8%) 87 | if (pwmAspeed > 5) { // if PWM output is more than 5 (about 2%) 88 | pwmAspeed = 0; // reduce PWM output by 20 (about 7.8%) 89 | } 90 | } 91 | } else if (cm<1000){ // at less than 1 meter 92 | dirALowForward = LOW; // Direction: forward 93 | brakeAHigh = LOW; // Brake: off 94 | if (carSpeed<3){ // if carspeed is less than 20 95 | if (pwmAspeed < 200) { // if PWM is less than 245 (about 96%) 96 | pwmAspeed += 20; // increase PWM by 20 (about 7.8%) 97 | } 98 | }else if (carSpeed>3){ // if carspeed is more than 20 (about 7.8%) 99 | if (pwmAspeed > 5) { // if PWM output is more than 5 (about 2%) 100 | pwmAspeed -= 20; // reduce PWM output by 20 (about 7.8%) 101 | } 102 | } 103 | } else { // at more than 1 meter 104 | dirALowForward = LOW; // Direction: forward 105 | brakeAHigh = LOW; // Brake: off 106 | if (carSpeed<3){ // if carspeed is less than 20 107 | if (pwmAspeed < 255) { // if PWM is less than 245 (about 96%) 108 | pwmAspeed += 20; // increase PWM by 20 (about 7.8%) 109 | } 110 | }else if (carSpeed>3){ // if carspeed is more than 20 (about 7.8%) 111 | if (pwmAspeed > 5) { // if PWM output is more than 5 (about 2%) 112 | pwmAspeed -= 20; // reduce PWM output by 20 (about 7.8%) 113 | } 114 | } 115 | } 116 | 117 | if (pwmAspeed > 255) { 118 | pwmAspeed = 255; // Makes sure we never give more than 100% 119 | } 120 | if (pwmAspeed < 0) { 121 | pwmAspeed = 0; // Makes sure we never give less than 0% 122 | } 123 | 124 | Serial.print(inches); 125 | Serial.print(" in, "); 126 | Serial.print(cm); 127 | Serial.print(" cm, "); 128 | Serial.print(lastCm); 129 | Serial.print(" lastcm, "); 130 | Serial.print(carSpeed); 131 | Serial.print(" car speed, "); 132 | Serial.print(pwmAspeed); 133 | Serial.print(" pwmAspeed, "); 134 | Serial.print(dirALowForward); 135 | Serial.println(); 136 | 137 | digitalWrite(motorAdir, dirALowForward); // Tell Motor A to go forward or reverse 138 | digitalWrite(motorAbrk, brakeAHigh); // Apply or release Motor A's brakes 139 | digitalWrite(motorBdir, dirBLowLeft); // Tell Motor B to turn left or right 140 | digitalWrite(motorBbrk, brakeBHigh); // Apply or release Motor B's steering brakes 141 | analogWrite(motorApwm, pwmAspeed); // Apply PWM output to Motor A as set above 142 | 143 | delay(pingDelay); // Wait 0.1s, which is necessary for ultrasonic ping operation. Depending on the amount of code, 144 | // this should be reduced. 145 | } 146 | 147 | 148 | // copied from ultrasonic ping 149 | // Sound moves 1 inch every 74 microseconds. Divide by 2 to remove the sound's return distance 150 | long microsecondsToInches(long microseconds) 151 | { 152 | return microseconds / 74 / 2; 153 | } 154 | 155 | // Sound moves 1 centimeter every 29 microseconds. Divide by 2 to remove the sound's return distance 156 | long microsecondsToCentimeters(long microseconds) 157 | { 158 | return microseconds / 29 / 2; 159 | } 160 | -------------------------------------------------------------------------------- /motor03/motor03.ino: -------------------------------------------------------------------------------- 1 | const int motorApwm = 3; // Motor A output pin (hardwired on motor shield) 2 | const int pingPin = 7; // pin used by the PING sensor 3 | const int motorBbrk = 8; // Motor A output pin (hardwired on motor shield) 4 | const int motorAbrk = 9; // Motor A output pin (hardwired on motor shield) 5 | const int buttonPin = 10; // the number of the pushbutton pin 6 | const int motorBpwm = 11; // Motor A output pin (hardwired on motor shield) 7 | const int motorAdir = 12; // Motor A output pin (hardwired on motor shield) 8 | const int motorBdir = 13; // Motor A output pin (hardwired on motor shield) 9 | const int motorAsns = A0; // Motor A output pin (hardwired on motor shield) 10 | const int motorBsns = A1; // Motor A output pin (hardwired on motor shield) 11 | 12 | void setup() { 13 | //Set up the motors for the correct outputs 14 | pinMode(motorAdir, OUTPUT); 15 | pinMode(motorApwm, OUTPUT); 16 | pinMode(motorAbrk, OUTPUT); 17 | pinMode(motorAsns, INPUT); 18 | pinMode(motorBdir, OUTPUT); 19 | pinMode(motorBpwm, OUTPUT); 20 | pinMode(motorBbrk, OUTPUT); 21 | pinMode(motorBsns, INPUT); 22 | pinMode(buttonPin, INPUT); 23 | 24 | } 25 | 26 | void loop() { 27 | long duration, inches, cm; 28 | int brakeAHigh = LOW; 29 | int pwmAspeed = 255; 30 | int dirALowForward = LOW; 31 | 32 | int brakeBHigh = LOW; 33 | int pwmBturn = 0; 34 | int dirBLowLeft = LOW; 35 | 36 | long lastCm = 14; 37 | long carSpeed = 0; 38 | 39 | digitalWrite(motorAdir, dirALowForward); 40 | digitalWrite(motorAbrk, brakeAHigh); 41 | digitalWrite(motorBdir, dirBLowLeft); 42 | digitalWrite(motorBbrk, brakeBHigh); 43 | 44 | 45 | analogWrite(motorApwm, pwmAspeed); 46 | digitalWrite(motorAbrk, brakeAHigh); 47 | 48 | delay(100); 49 | } 50 | -------------------------------------------------------------------------------- /motor04/motor04.ino: -------------------------------------------------------------------------------- 1 | const int motorApwm = 3; // Motor A output pin (hardwired on motor shield) 2 | const int pingPin = 7; // pin used by the PING sensor 3 | const int motorBbrk = 8; // Motor B brake pin (hardwired on motor shield) 4 | const int motorAbrk = 9; // Motor A brake pin (hardwired on motor shield) 5 | const int motorBpwm = 11; // Motor B output pin (hardwired on motor shield) 6 | const int motorAdir = 12; // Motor A direction pin (hardwired on motor shield) 7 | const int motorBdir = 13; // Motor B direction pin (hardwired on motor shield) 8 | const int motorAsns = A0; // Motor A sensor pin (hardwired on motor shield) 9 | const int motorBsns = A1; // Motor B sensor pin (hardwired on motor shield) 10 | 11 | int brakeAHigh = LOW; // turn off the parking brake 12 | int pwmAspeed = 0; // set motor speed to 0/255 13 | int dirALowForward = LOW; // Which direction the motor should spin 14 | //LOW = forward, HIGH = reverse 15 | int pingDelay = 100; // how long the processor should idle before continuing, 16 | // needed for ultrasonic ping to work 17 | 18 | int brakeBHigh = LOW; // turn off the steering lock 19 | int pwmBturn = 0; // set steering motor speed to 0 20 | int dirBLowLeft = LOW; // Which direction the motor should spin 21 | //LOW = left?, HIGH = right? 22 | 23 | long lastCm = 14; // Used for speedometer 24 | long carSpeed = 0; // Used for speedometer 25 | 26 | 27 | void setup() { 28 | //Set up the motors for the correct outputs 29 | pinMode(motorAdir, OUTPUT); 30 | pinMode(motorApwm, OUTPUT); 31 | pinMode(motorAbrk, OUTPUT); 32 | pinMode(motorAsns, INPUT); 33 | pinMode(motorBdir, OUTPUT); 34 | pinMode(motorBpwm, OUTPUT); 35 | pinMode(motorBbrk, OUTPUT); 36 | pinMode(motorBsns, INPUT); 37 | // pinMode(buttonPin, INPUT); 38 | 39 | Serial.begin(9600); // To see the values on the PC 40 | } 41 | 42 | void loop() { 43 | long duration, inches, cm; // These 3 variables are used for the 44 | // Distance sensor's math functions below 45 | 46 | // copied from ultrasonic_range 47 | pinMode(pingPin, OUTPUT); // Set the Ping pin to Send 48 | digitalWrite(pingPin, LOW); // Clear the line to the sensor 49 | delayMicroseconds(2); // wait 0.002 seconds 50 | digitalWrite(pingPin, HIGH); // send the ping 51 | delayMicroseconds(5); // wait 0.005 seconds 52 | digitalWrite(pingPin, LOW); // Clear the line to the sensor 53 | // We sent that ping 0.007 seconds ago 54 | pinMode(pingPin, INPUT); // Set the Ping pin to Receive 55 | duration = pulseIn(pingPin, HIGH); // set the variable named Duration to 56 | // be the number of microseconds until the 57 | // ultrasonic ping comes back 58 | 59 | inches = microsecondsToInches(duration); // Calls the function that converts microseconds to inches 60 | cm = microsecondsToCentimeters(duration);// Calls the function that converts microseconds to centimeters 61 | carSpeed = lastCm - cm; //Speedometer. Sets carSpeed to be the previous distance minus the current distance to the wall. 62 | lastCm = cm; // Replaces the previous distance to wall with current distance to wall. 63 | 64 | // Depending on the distance and car speed, speed up or slow down 65 | if (cm<30) { // if we're closer than 30cm 66 | if (carSpeed<3){ // if speed is less than 3 67 | dirALowForward = HIGH; // Direction: reverse 68 | brakeAHigh = LOW; // Brake: off 69 | if (pwmAspeed < 128) { // if PWM output is less than 128 (about 50%) 70 | pwmAspeed += 5; // increase PWM output by 5 (about 2%) 71 | } 72 | }else if (carSpeed>3){ // if speed is more than 3 73 | dirALowForward = HIGH; // Direction: reverse 74 | brakeAHigh = HIGH; // Brakes on 75 | if (pwmAspeed < 128) { //if PWM output is more than 128 (about 50%) 76 | pwmAspeed += 5; // increase PWM output by 5 (about 2%) 77 | } 78 | } 79 | } else { // at less than 30cm 80 | dirALowForward = LOW; // Direction: forward 81 | brakeAHigh = LOW; // Brake: off 82 | pwmAspeed = map(cm,30,300,20,255); 83 | 84 | } 85 | 86 | // } else if (cm<1000){ // at less than 1 meter 87 | // dirALowForward = LOW; // Direction: forward 88 | // brakeAHigh = LOW; // Brake: off 89 | // if (carSpeed<3){ // if carspeed is less than 20 90 | // if (pwmAspeed < 200) { // if PWM is less than 245 (about 96%) 91 | // pwmAspeed += 20; // increase PWM by 20 (about 7.8%) 92 | // } 93 | // }else if (carSpeed>3){ // if carspeed is more than 20 (about 7.8%) 94 | // if (pwmAspeed > 5) { // if PWM output is more than 5 (about 2%) 95 | // pwmAspeed -= 20; // reduce PWM output by 20 (about 7.8%) 96 | // } 97 | // } 98 | // } else { // at more than 1 meter 99 | // dirALowForward = LOW; // Direction: forward 100 | // brakeAHigh = LOW; // Brake: off 101 | // if (carSpeed<3){ // if carspeed is less than 20 102 | // if (pwmAspeed < 255) { // if PWM is less than 245 (about 96%) 103 | // pwmAspeed += 20; // increase PWM by 20 (about 7.8%) 104 | // } 105 | // }else if (carSpeed>3){ // if carspeed is more than 20 (about 7.8%) 106 | // if (pwmAspeed > 5) { // if PWM output is more than 5 (about 2%) 107 | // pwmAspeed -= 20; // reduce PWM output by 20 (about 7.8%) 108 | // } 109 | // } 110 | // } 111 | 112 | if (pwmAspeed > 255) { 113 | pwmAspeed = 255; // Makes sure we never give more than 100% 114 | } 115 | if (pwmAspeed < 0) { 116 | pwmAspeed = 0; // Makes sure we never give less than 0% 117 | } 118 | 119 | Serial.print(inches); 120 | Serial.print(" in, "); 121 | Serial.print(cm); 122 | Serial.print(" cm, "); 123 | Serial.print(lastCm); 124 | Serial.print(" lastcm, "); 125 | Serial.print(carSpeed); 126 | Serial.print(" car speed, "); 127 | Serial.print(pwmAspeed); 128 | Serial.print(" pwmAspeed, "); 129 | Serial.print(dirALowForward); 130 | Serial.println(); 131 | 132 | digitalWrite(motorAdir, dirALowForward); // Tell Motor A to go forward or reverse 133 | digitalWrite(motorAbrk, brakeAHigh); // Apply or release Motor A's brakes 134 | digitalWrite(motorBdir, dirBLowLeft); // Tell Motor B to turn left or right 135 | digitalWrite(motorBbrk, brakeBHigh); // Apply or release Motor B's steering brakes 136 | analogWrite(motorApwm, pwmAspeed); // Apply PWM output to Motor A as set above 137 | 138 | delay(pingDelay); // Wait 0.1s, which is necessary for ultrasonic ping operation. Depending on the amount of code, 139 | // this should be reduced. 140 | } 141 | 142 | 143 | // copied from ultrasonic ping 144 | // Sound moves 1 inch every 74 microseconds. Divide by 2 to remove the sound's return distance 145 | long microsecondsToInches(long microseconds) 146 | { 147 | return microseconds / 74 / 2; 148 | } 149 | 150 | // Sound moves 1 centimeter every 29 microseconds. Divide by 2 to remove the sound's return distance 151 | long microsecondsToCentimeters(long microseconds) 152 | { 153 | return microseconds / 29 / 2; 154 | } 155 | -------------------------------------------------------------------------------- /nerf01/nerf01.ino: -------------------------------------------------------------------------------- 1 | const int triggerPin = 1; // pin used for the trigger 2 | const int motorApwm = 3; // Motor A output pin (hardwired on motor shield) 3 | const int pingPin = 7; // pin used by the PING sensor 4 | const int motorBbrk = 8; // Motor A output pin (hardwired on motor shield) 5 | const int motorAbrk = 9; // Motor A output pin (hardwired on motor shield) 6 | const int motorBpwm = 11; // Motor A output pin (hardwired on motor shield) 7 | const int motorAdir = 12; // Motor A output pin (hardwired on motor shield) 8 | const int motorBdir = 13; // Motor A output pin (hardwired on motor shield) 9 | const int motorAsns = A0; // Motor A output pin (hardwired on motor shield) 10 | const int motorBsns = A1; // Motor A output pin (hardwired on motor shield) 11 | 12 | int brakeAHigh = LOW; 13 | int pwmAout = 0; 14 | int dirALowForward = HIGH; 15 | 16 | int brakeBHigh = LOW; 17 | int pwmBout = 0; 18 | int dirBLowLeft = LOW; 19 | 20 | int fireDist = 1800; 21 | 22 | 23 | 24 | void setup() { 25 | pinMode(triggerPin, OUTPUT); 26 | //Set up the motors for the correct outputs 27 | pinMode(motorAdir, OUTPUT); 28 | pinMode(motorApwm, OUTPUT); 29 | pinMode(motorAbrk, OUTPUT); 30 | pinMode(motorAsns, INPUT); 31 | pinMode(motorBdir, OUTPUT); 32 | pinMode(motorBpwm, OUTPUT); 33 | pinMode(motorBbrk, OUTPUT); 34 | pinMode(motorBsns, INPUT); 35 | 36 | } 37 | 38 | void loop() 39 | { 40 | // establish variables for duration of the ping, 41 | // and the distance result in inches and centimeters: 42 | long duration, inches, cm; 43 | 44 | // The PING))) is triggered by a HIGH pulse of 2 or more microseconds. 45 | // Give a short LOW pulse beforehand to ensure a clean HIGH pulse: 46 | pinMode(pingPin, OUTPUT); 47 | digitalWrite(pingPin, LOW); 48 | delayMicroseconds(2); 49 | digitalWrite(pingPin, HIGH); 50 | delayMicroseconds(5); 51 | digitalWrite(pingPin, LOW); 52 | 53 | pinMode(pingPin, INPUT); 54 | duration = pulseIn(pingPin, HIGH); 55 | 56 | 57 | if (duration 11 | 12 | // These are the pins that we are using to connect to the Xbee 13 | #define XBEE_SELECT SS 14 | #define XBEE_ATN 6 15 | #define XBEE_RESET 5 16 | #define XBEE_DOUT 8 17 | 18 | // XBee object 19 | XbeeWifi xbee; 20 | 21 | 22 | // Keep track of 10 second intervals at which point we'll initiate scans 23 | unsigned long next_scan; 24 | 25 | // Setup routine 26 | void setup() 27 | { 28 | // Serial at 57600 29 | Serial.begin(57600); 30 | 31 | // Initialize the xbee 32 | Serial.println(XBEE_SELECT); 33 | Serial.println(XBEE_ATN); 34 | Serial.println(XBEE_RESET); 35 | Serial.println(XBEE_DOUT); 36 | bool result = xbee.init(XBEE_SELECT, XBEE_ATN, XBEE_RESET, XBEE_DOUT); 37 | Serial.println(result); 38 | 39 | if (!result) { 40 | // Something failed 41 | Serial.println(F("XBee Init Failed")); 42 | while (true) { /* Loop forever - game over */} 43 | } else { 44 | // Register for incoming scan data 45 | xbee.register_scan_callback(inbound_scan); 46 | 47 | Serial.println("XBee found and configured"); 48 | 49 | } 50 | 51 | next_scan = millis(); 52 | 53 | } 54 | 55 | // Main run loop 56 | void loop() 57 | { 58 | // Initiate a scan every ten seconds 59 | if (millis() >= next_scan) { 60 | if (xbee.initiateScan()) { 61 | Serial.println(F("Scan initiated")); 62 | } else { 63 | Serial.println(F("Failed to initiate scan")); 64 | } 65 | next_scan = millis() + 10000; 66 | } 67 | 68 | // Process the xbee 69 | xbee.process(); 70 | } 71 | 72 | // Receive and output scan data 73 | void inbound_scan(uint8_t encryption_mode, int rssi, char *ssid) 74 | { 75 | Serial.print(F("Scan Information, SSID=")); 76 | Serial.print(ssid); 77 | Serial.print(F(", RSSI=-")); 78 | Serial.print(rssi, DEC); 79 | Serial.print(F("dB, Security=")); 80 | switch(encryption_mode) { 81 | case XBEE_SEC_ENCTYPE_NONE : Serial.println(F("none")); break; 82 | case XBEE_SEC_ENCTYPE_WEP : Serial.println(F("wep")); break; 83 | case XBEE_SEC_ENCTYPE_WPA : Serial.println(F("wpa")); break; 84 | case XBEE_SEC_ENCTYPE_WPA2 : Serial.println(F("wpa2")); break; 85 | default : Serial.println(F("Unknown")); break; 86 | } 87 | } 88 | 89 | -------------------------------------------------------------------------------- /rand_num_7seg_led/rand_num_7seg_led.ino: -------------------------------------------------------------------------------- 1 | //random number generator 2 | //set up 7-segment 3 | int top = 5; // top LED of 7-segment 4 | int upleft = 6; // upper left LED of 7-segment 5 | int upright = 2; // upper right LED of 7-segment 6 | int mid = 8; // upper right LED of 7-segment 7 | int botleft = 9; // lower left LED of 7-segment 8 | int botright = 12; // lower right LED of 7-segment 9 | int bottom = 11; // bottom LED of 7-segment 10 | 11 | int buttonPin = 1; 12 | 13 | int randnum = 0; 14 | int buttonState = 0; // variable for reading the pushbutton status 15 | 16 | 17 | void setup() { 18 | pinMode(top, OUTPUT); 19 | pinMode(upleft, OUTPUT); 20 | pinMode(upright, OUTPUT); 21 | pinMode(mid, OUTPUT); 22 | pinMode(botleft, OUTPUT); 23 | pinMode(botright, OUTPUT); 24 | pinMode(bottom, OUTPUT); 25 | pinMode(buttonPin, OUTPUT); 26 | 27 | pinMode(buttonPin, INPUT); 28 | 29 | // digitalWrite(top, LOW); 30 | // digitalWrite(upleft, LOW); 31 | // digitalWrite(upright, LOW); 32 | // digitalWrite(mid, LOW); 33 | // digitalWrite(botleft, LOW); 34 | // digitalWrite(botright, LOW); 35 | // digitalWrite(bottom, LOW); 36 | 37 | } 38 | 39 | void loop() { 40 | // 41 | buttonState = digitalRead(buttonPin); 42 | if (buttonState == LOW) { 43 | ////randnum = random(0,10); 44 | //randnum += 1; 45 | digitalWrite(top, LOW); 46 | } 47 | // 48 | //if (randnum = 0) { 49 | // digitalWrite(top, HIGH); 50 | // digitalWrite(upleft, HIGH); 51 | // digitalWrite(upright, HIGH); 52 | // digitalWrite(mid, LOW); 53 | // digitalWrite(botleft, HIGH); 54 | // digitalWrite(botright, HIGH); 55 | // digitalWrite(bottom, HIGH); 56 | //} else if (randnum = 1) { 57 | // digitalWrite(top, LOW); 58 | // digitalWrite(upleft, LOW); 59 | // digitalWrite(upright, HIGH); 60 | // digitalWrite(mid, LOW); 61 | // digitalWrite(botleft, LOW); 62 | // digitalWrite(botright, HIGH); 63 | // digitalWrite(bottom, LOW); 64 | //} else if (randnum = 2) { 65 | // digitalWrite(top, HIGH); 66 | // digitalWrite(upleft, LOW); 67 | // digitalWrite(upright, HIGH); 68 | // digitalWrite(mid, HIGH); 69 | // digitalWrite(botleft, HIGH); 70 | // digitalWrite(botright, LOW); 71 | // digitalWrite(bottom, HIGH); 72 | //} else if (randnum = 3) { 73 | // digitalWrite(top, HIGH); 74 | // digitalWrite(upleft, LOW); 75 | // digitalWrite(upright, HIGH); 76 | // digitalWrite(mid, HIGH); 77 | // digitalWrite(botleft, LOW); 78 | // digitalWrite(botright, HIGH); 79 | // digitalWrite(bottom, HIGH); 80 | //} else if (randnum = 4) { 81 | // digitalWrite(top, LOW); 82 | // digitalWrite(upleft, HIGH); 83 | // digitalWrite(upright, HIGH); 84 | // digitalWrite(mid, HIGH); 85 | // digitalWrite(botleft, HIGH); 86 | // digitalWrite(botright, LOW); 87 | // digitalWrite(bottom, LOW); 88 | //} else if (randnum = 5) { 89 | // digitalWrite(top, HIGH); 90 | // digitalWrite(upleft, HIGH); 91 | // digitalWrite(upright, LOW); 92 | // digitalWrite(mid, HIGH); 93 | // digitalWrite(botleft, LOW); 94 | // digitalWrite(botright, HIGH); 95 | // digitalWrite(bottom, HIGH); 96 | //} else if (randnum = 6) { 97 | // digitalWrite(top, HIGH); 98 | // digitalWrite(upleft, HIGH); 99 | // digitalWrite(upright, LOW); 100 | // digitalWrite(mid, HIGH); 101 | // digitalWrite(botleft, HIGH); 102 | // digitalWrite(botright, HIGH); 103 | // digitalWrite(bottom, HIGH); 104 | //} else if (randnum = 7) { 105 | // digitalWrite(top, HIGH); 106 | // digitalWrite(upleft, LOW); 107 | // digitalWrite(upright, HIGH); 108 | // digitalWrite(mid, LOW); 109 | // digitalWrite(botleft, LOW); 110 | // digitalWrite(botright, HIGH); 111 | // digitalWrite(bottom, LOW); 112 | //} else if (randnum = 8) { 113 | digitalWrite(top, HIGH); 114 | digitalWrite(upleft, HIGH); 115 | digitalWrite(upright, HIGH); 116 | digitalWrite(mid, HIGH); 117 | digitalWrite(botleft, HIGH); 118 | digitalWrite(botright, HIGH); 119 | digitalWrite(bottom, HIGH); 120 | //} else if (randnum = 9) { 121 | // digitalWrite(top, HIGH); 122 | // digitalWrite(upleft, HIGH); 123 | // digitalWrite(upright, HIGH); 124 | // digitalWrite(mid, HIGH); 125 | // digitalWrite(botleft, LOW); 126 | // digitalWrite(botright, HIGH); 127 | // digitalWrite(bottom, HIGH); 128 | //} else { 129 | // digitalWrite(top, LOW); 130 | // digitalWrite(upleft, LOW); 131 | // digitalWrite(upright, LOW); 132 | // digitalWrite(mid, LOW); 133 | // digitalWrite(botleft, LOW); 134 | // digitalWrite(botright, LOW); 135 | // digitalWrite(bottom, LOW); 136 | //}; 137 | } 138 | 139 | -------------------------------------------------------------------------------- /sdcard01/sdcard01/sdcard01.ino: -------------------------------------------------------------------------------- 1 | // ** MOSI - pin 11 2 | // ** MISO - pin 12 3 | // ** CLK - pin 13 4 | 5 | #include 6 | #include 7 | 8 | // set up variables using the SD utility library functions: 9 | Sd2Card card; 10 | SdVolume volume; 11 | SdFile root; 12 | File myFile; 13 | 14 | // change this to match your SD shield or module; 15 | // Arduino Ethernet shield: pin 4 16 | const int chipSelect = 4; 17 | LiquidCrystal lcd(1, 6, 5, 0, 3, 2); // LCD input pins 4, 6, 11, 12, 13, 14 18 | 19 | void setup() { 20 | // set up the LCD's number of columns and rows: 21 | lcd.begin(16, 2); 22 | // Print a message to the LCD. 23 | lcd.setCursor(0, 0); 24 | lcd.print("Type Vol MB"); 25 | // lcd.setCursor(0, 1); 26 | // lcd.print("volumesize"); 27 | 28 | 29 | // Open serial communications and wait for port to open: 30 | // Serial.begin(9600); 31 | // Serial.print("\nInitializing SD card..."); 32 | // lcd.setCursor(0, 0); 33 | // lcd.print("Initializing SD card..."); 34 | // On the Ethernet Shield, CS is pin 4. It's set as an output by default. 35 | // Note that even if it's not used as the CS pin, the hardware SS pin 36 | // (10 on most Arduino boards, 53 on the Mega) must be left as an output 37 | // or the SD library functions will not work. 38 | pinMode(10, OUTPUT); // change this to 53 on a mega 39 | 40 | 41 | // we'll use the initialization code from the utility libraries 42 | // since we're just testing if the card is working! 43 | 44 | if (!card.init(SPI_HALF_SPEED, chipSelect)) { 45 | lcd.setCursor(0, 1); 46 | lcd.print("initialization failed."); 47 | // Serial.println("initialization failed. Things to check:"); 48 | // Serial.println("* is a card is inserted?"); 49 | // Serial.println("* Is your wiring correct?"); 50 | // Serial.println("* did you change the chipSelect pin to match your shield or module?"); 51 | return; 52 | } else { 53 | lcd.setCursor(0, 1); 54 | lcd.print("OK"); 55 | // Serial.println("Wiring is correct and a card is present."); 56 | delay(500); 57 | } 58 | 59 | // print the type of card 60 | // Serial.print("\nCard type: "); 61 | switch(card.type()) { 62 | case SD_CARD_TYPE_SD1: 63 | lcd.setCursor(0, 1); 64 | lcd.print("SD1"); 65 | // Serial.println("SD1"); 66 | break; 67 | case SD_CARD_TYPE_SD2: 68 | lcd.setCursor(0, 1); 69 | lcd.print("SD2"); 70 | // Serial.println("SD2"); 71 | break; 72 | case SD_CARD_TYPE_SDHC: 73 | lcd.setCursor(0, 1); 74 | lcd.print("SDHC"); 75 | // Serial.println("SDHC"); 76 | break; 77 | default: 78 | lcd.setCursor(0, 1); 79 | lcd.print("UNK"); 80 | // Serial.println("Unknown"); 81 | } 82 | 83 | // Now we will try to open the 'volume'/'partition' - it should be FAT16 or FAT32 84 | if (!volume.init(card)) { 85 | lcd.setCursor(0, 1); 86 | lcd.print("No Card"); 87 | // Serial.println("Could not find FAT16/FAT32 partition.\nMake sure you've formatted the card"); 88 | return; 89 | } 90 | 91 | 92 | // print the type and size of the first FAT-type volume 93 | uint32_t volumesize; 94 | lcd.setCursor(5, 1); 95 | lcd.print("FAT"); 96 | lcd.print(volume.fatType(), DEC); 97 | // Serial.print("\nVolume type is FAT"); 98 | // Serial.println(volume.fatType(), DEC); 99 | // Serial.println(); 100 | 101 | volumesize = volume.blocksPerCluster(); // clusters are collections of blocks 102 | volumesize *= volume.clusterCount(); // we'll have a lot of clusters 103 | volumesize *= 512; // SD card blocks are always 512 bytes 104 | // Serial.print("Volume size (bytes): "); 105 | // Serial.println(volumesize); 106 | // Serial.print("Volume size (Kbytes): "); 107 | volumesize /= 1024; 108 | // Serial.println(volumesize); 109 | // Serial.print("Volume size (Mbytes): "); 110 | volumesize /= 1024; 111 | lcd.setCursor(12, 1); 112 | lcd.print(volumesize); 113 | // Serial.println(volumesize); 114 | 115 | delay(5000); 116 | // Serial.println("\nFiles found on the card (name, date and size in bytes): "); 117 | lcd.setCursor(0, 0); 118 | lcd.print(" "); 119 | lcd.setCursor(0, 0); 120 | lcd.print("Files found:"); 121 | lcd.setCursor(0, 1); 122 | lcd.print(" "); 123 | lcd.setCursor(0, 1); 124 | lcd.print(root.openRoot(volume)); 125 | 126 | 127 | myFile = SD.open("BACON.TXT"); 128 | if (myFile) { 129 | lcd.setCursor(0, 0); 130 | lcd.print(" "); 131 | lcd.setCursor(0, 0); 132 | lcd.print("BACON.TXT:"); 133 | lcd.setCursor(0, 1); 134 | lcd.print(" "); 135 | lcd.setCursor(0, 1); 136 | 137 | // read from the file until there's nothing else in it: 138 | while (myFile.available()) { 139 | lcd.print(myFile.read()); 140 | } 141 | // close the file: 142 | myFile.close(); 143 | } else { 144 | // if the file didn't open, print an error: 145 | lcd.setCursor(0, 0); 146 | lcd.print(" "); 147 | lcd.setCursor(0, 0); 148 | lcd.print("error opening BACON.TXT"); 149 | lcd.setCursor(0, 1); 150 | lcd.print(" "); 151 | lcd.setCursor(0, 1); 152 | } 153 | 154 | 155 | 156 | 157 | 158 | } 159 | 160 | 161 | void loop() { 162 | 163 | } 164 | -------------------------------------------------------------------------------- /wifi01/wifi01.ino: -------------------------------------------------------------------------------- 1 | #define XBEE_RESET 20 2 | #define XBEE_ATN 2 3 | #define XBEE_SELECT SS 4 | #define XBEE_DOUT 23 5 | 6 | XbeeWifi xbee; 7 | 8 | 9 | 10 | void setup() { 11 | // put your setup code here, to run once: 12 | if (!xbee.init(XBEE_SELECT, XBEE_ATN, XBEE_RESET, XBEE_DOUT)) { 13 | // Failed to initialize 14 | } 15 | 16 | xbee.at_cmd_byte(XBEE_AT_NET_TYPE, XBEE_NET_TYPE_IBSS_INFRASTRUCTURE); 17 | xbee.at_cmd_byte(XBEE_AT_NET_IPPROTO, XBEE_NET_IPPROTO_TCP); 18 | xbee.at_cmd_str(XBEE_AT_NET_SSID, "my_network"); 19 | xbee.at_cmd_byte(XBEE_AT_NET_ADDRMODE, XBEE_NET_ADDRMODE_DHCP); 20 | xbee.at_cmd_short(XBEE_AT_ADDR_SERIAL_COM_SERVICE_PORT, 12345); 21 | xbee.at_cmd_byte(XBEE_AT_SEC_ENCTYPE, XBEE_SEC_ENCTYPE_WPA2); 22 | xbee.at_cmd_str(XBEE_AT_SEC_KEY, "MyVerySecretPassphrase"); 23 | 24 | } 25 | 26 | void loop() { 27 | // put your main code here, to run repeatedly: 28 | 29 | } 30 | 31 | //Callbacks: 32 | //IP Data Reception 33 | //To register a function to receive inbound IP data register a function of the following prototype: 34 | // void my_ip_inbound_function(uint8_t *data, int len, s_rxinfo *info); 35 | //Using the register_ip_data_callback method: 36 | // xbee.register_ip_data_callback(my_ip_inbound_function); 37 | // 38 | //Modem Status Reception 39 | //To register for modem status updates, register a function of the following prototype: 40 | // void my_modem_status_function(uint8_t status); 41 | //Using the register_status_callback method 42 | // xbee.register_status_callback(my_modem_status_function); 43 | // 44 | //Remote Data Sample callback 45 | //To register for sample callback, register a function of the following prototype: 46 | // void my_sample_callback(s_sample *sample); 47 | //Using the register_sample_callback method 48 | // xbee.register_sample_callback(sample); 49 | // 50 | //Network Scan callback 51 | //To register for scan callback, register a function of the following prototype: 52 | // void my_callback(uint8_t encryption_mode, int rssi, char *ssid); 53 | //Using the register_scan_callback method 54 | // xbee.register_scan_callback(my_scan_callback); 55 | //To scan for networks you must then call initiateScan() 56 | // xbee.initiateScan() 57 | // 58 | 59 | -------------------------------------------------------------------------------- /xbeewire.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Gilgamech/Arduino/81e67fb3e10975a872f6095c4068236a550e93b2/xbeewire.jpg --------------------------------------------------------------------------------