Posts

temp and pressure sensor

#include <Wire.h> #define BMP180_ADDRESS 0x77 // I2C address of BMP180 const float p0 = 101325; // Pressure at sea level (Pa) float altitude; const unsigned char OSS = 0; // Oversampling Setting // Read 1 byte from the BMP180 at 'address' char bmp180Read(unsigned char address) {  unsigned char data;  Wire.beginTransmission(BMP180_ADDRESS);  Wire.write(address);  Wire.endTransmission();  Wire.requestFrom(BMP180_ADDRESS, 1);  while(!Wire.available())  ;  return Wire.read(); } // Read 2 bytes from the BMP180 // First byte will be from 'address' // Second byte will be from 'address'+1 int bmp180ReadInt(unsigned char address) {  unsigned char msb, lsb;  Wire.beginTransmission(BMP180_ADDRESS);  Wire.write(address);  Wire.endTransmission();  Wire.requestFrom(BMP180_ADDRESS, 2);  while(Wire.available()<2)  ;  msb = Wire.read();  lsb = Wire.read();  return (int) ...

interrup and sound lab

//Use Hardware and Timer Interrupts for Fun with Sound //Include the TimerOne library #include <TimerOne.h> //Button pins const int BUTTON_INT =0; //Interrupt 0 (pin 2 on the Uno) const int SPEAKER =12; //Speaker on pin 12 //Music keys #define NOTE_C 65 #define NOTE_D 73 #define NOTE_E 82 #define NOTE_F 87 #define NOTE_G 98 #define NOTE_A 110 #define NOTE_B 123 //Volatile variables can change inside interrupts volatile int key = NOTE_C; volatile int octave_multiplier = 1; void setup() { //Set up serial Serial.begin(9600);  pinMode (SPEAKER, OUTPUT); //The pin is inverted, so we want to look at the rising edge attachInterrupt(BUTTON_INT, changeKey, RISING);  //Set up timer interrupt Timer1.initialize(500000); // (.5 seconds) Timer1.attachInterrupt(changePitch); //Runs "changePitch" on each                                      //timer interupt } v...

SD card : read & write

//Write to SD card #include  <SD.h> //Set by default for the SD card library //MOSI = pin 11 //MISO = pin 12 //SCLK = pin 13 //We always need to set the CS Pin const int CS_PIN = 10; void setup()               { Serial.begin(9600); Serial.println("Initializing Card"); //CS pin is an output pinMode(CS_PIN, OUTPUT); if (!SD.begin(CS_PIN))                         {                           Serial.println("Card Failure");                           return;                           } Serial.println("Card Ready");                 } void loop()            { long timeStamp = millis(); String dataString = ...

real time & EEPROM lab

// Date and time functions using a DS1307 RTC connected via I2C and Wire lib #include <Wire.h> #include "RTClib.h" RTC_DS1307 rtc; void setup () { Serial.begin(57600); if (! rtc.begin()) { Serial.println("Couldn't find RTC"); while (1); } rtc.adjust(DateTime(F(__DATE__), F(__TIME__))); // This line sets the RTC with an explicit date & time, for example to s // January 21, 2014 at 3am you would call: // rtc.adjust(DateTime(2014, 1, 21, 3, 0, 0)); } void loop () { DateTime now = rtc.now(); Serial.print(now.year(), DEC); Serial.print('/'); Serial.print(now.month(), DEC); Serial.print('/'); Serial.print(now.day(), DEC); Serial.print(" ("); Serial.print(now.hour(), DEC); Serial.print(':'); Serial.print(now.minute(), DEC); Serial.print(':'); Serial.print(now.second(), DEC); Serial.println(); delay(1000); } //////////////////////////////////////////////////////////////////////...

toy project #2 light & temp configurator

// include the library code: #include <LiquidCrystal.h> #include <Wire.h> // initialize the library with the numbers of the interface pins LiquidCrystal lcd(8,9,4, 5, 6,7); //TMP36 Pin Variables int temperaturePin = 0; //the analog pin the TMP36's Vout (sense) pin is connected to the resolution is 10 mV / degree centigrade(500 mV offset) to make negative temperatures an option //PhotoResistor Pin int lightPin = 1; //the analog pin the photoresistor is connected to the photoresistor is not calibrated to any units so this is simply a raw sensor value (relative light) //led for light sensor int lcdRed = 3;   //the pin the LED is connected to int lcdBlue = 5;   //the pin the LED is connected to //pir sensor const int PIR=10;  void setup() {   // set up the LCD's number of columns and rows: lcd.begin(16,2); Serial.begin(9600);  //Start the serial connection with the copmuter            ...

pointers code no lb

#include <stdio.h> #include <string.h> #define MAX_SIZE 1000 #define FILENAME "DNAString1.txt" int main(void) { /* Declare and initialize variables. */ int count=0; char long_str[MAX_SIZE]; char short_str[MAX_SIZE]; FILE *DNA; DNA = fopen(FILENAME, "r"); if (DNA == NULL) printf("Error opening input file. \n"); else { fscanf(DNA,"%s",long_str); printf("Enter in short DNA string: \n"); scanf("%s",short_str); char *ptr1=long_str, *ptr2=short_str; int short_length = strlen(short_str); int long_length = strlen(long_str); if (short_length > long_length) printf("Error: Short string must be smaller than long string.\n"); else { printf("\nLong DNA String: %s \n", long_str); printf("Short DNA String: %s \n", short_str); while ((ptr1=strstr(ptr1,ptr2)) != NULL) { //printf("location of the string \n", ptr1, long_str); printf("location %i \n...

RGB lab interrupt pin / 4 types of

//Use Hardware-Debounced Switch to Control Interrupt //Button pins const int BUTTON_INT =1; //Interrupt 1 (pin 3 on the Uno) const int RED =11; //Red LED on pin 11 const int GREEN =10; //Green LED on pin 10 const int BLUE =9; //Blue LED on pin 9 //Volatile variables can change inside interrupts volatile int selectedLED = RED; void setup() { pinMode (RED, OUTPUT); pinMode (GREEN, OUTPUT); pinMode (BLUE, OUTPUT); //The pin is inverted, so we want to look at the rising edge attachInterrupt(BUTTON_INT, swap, RISING); } void swap() { //Turn off the current LED analogWrite(selectedLED, 0); //Then, choose a new one. if (selectedLED == GREEN) selectedLED = RED; else if (selectedLED == RED) selectedLED = BLUE; else if (selectedLED == BLUE) selectedLED = GREEN; } void loop() {   for (int i = 0; i<256; i++)       {       analogWrite(selectedLED, i);       delay(10);       } for (int i = 255; i...