- •Practical embedded system programming
- •Void setup() {
- •In this firmware can be activated address bus a0, a1, a2 and a3
- •Void setup() {
- •Void setup() {
- •Void setup()
- •Void setup()
- •Void setup()
- •Void setup()
- •Void setup()
- •Void setup() {
- •Void setup(){
- •Void setup(){
- •Void setup()
- •Void setup()
- •Void setup()
- •Void setup()
- •Void setup()
- •Void setup() {
- •Void setup() {
- •Void setup(){
- •Void setup() {
- •Void setup() {
- •Void setup()
- •Void setup()
- •Void setup() {
- •Void setup() {
- •Void setup() {
- •Void setup() {
- •Void setup()
- •Void setup()
- •Void setup()
- •Void setup() {
- •Void setup() {
- •Void setup() {
- •Void setup() {
- •Void setup() {
- •Void setup() {
Void setup() {
Serial.begin(9600);
}
void loop() {
sendSMS(); //Send SMS
delay(5000); //Wait for few seconds
}
void sendSMS()
{
Serial.println("AT+CMGD=1"); //Delete privious sent SMS
delay(1000);
Serial.println("AT+CMGF=1"); //Set SMS configuration
delay(1000);
Serial.print("AT+CMGW="); //Write New SMS
Serial.write(34); //Double quotes ASCII Code
Serial.print("+9198--------"); //Enter Your Mobile number
Serial.write(34);
Serial.println(); //Send Cringe return
delay(1000);
Serial.println("Your message here"); //SMS Message to be sent
delay(1000);
Serial.write(26); //Cntrl+Z character code
delay(1000);
delay(1000);
Serial.println("AT+CMSS=1"); //Send SMS from memory location 1
delay(4000);
}
/*
* Pulse-width modulation - PWM
* Using microcontroller ATMEGA8
* Using microcontroller ATMEGA328P
*/
int osc_0 = 0; //
int CLK = 5; //
int val_0 = SS; //
int osc_1 = 1; //
int SYNC = 6; //
int val_1 = MOSI; //
int osc_2 = 2; //
int WS = 7; //
int val_2 = MISO; //
Void setup() {
// put your setup code here, to run once:
pinMode(CLK, OUTPUT ); //It functions the pin mode of output signal to clock frequency
pinMode(SYNC, OUTPUT); //It functions the pin mode of output signal to synchronization frequency
pinMode(WS, OUTPUT); //It functions the pin mode of output signal to word select output
}
void loop() {
// put your main code here, to run repeatedly:
val_0 = analogRead(CLK); //
analogWrite(CLK, (val_0/4)); //
val_1 = analogRead(SYNC); //
analogWrite(SYNC, (val_1/8)); //
val_2 = analogRead(WS); //
analogWrite(WS, (val_2/16)); //
}
Shall test liquid-crystal display which is based on organic light-emitting diodes (OzOLED).
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define OLED_RESET 4
Adafruit_SSD1306 display(OLED_RESET); //
// Pins
const int TRIG_PIN = 11; //
const int ECHO_PIN = 12; //
// Anything over 400 cm (23200 us pulse) is "out of range"
const unsigned int MAX_DIST = 23200, MIN_DIST = 150; //
float avgDist = 0, dist, cm,inches; //
int pingCount,avgCount; //
unsigned long pulse_width; //
Void setup() {
//lcd.Begin(16,2)
// The Trigger pin will tell the sensor to range find
pinMode(TRIG_PIN, OUTPUT);
digitalWrite(TRIG_PIN, LOW);
// We'll use the serial monitor to view the sensor output
Serial.begin(9600);
// by default, we'll generate the high voltage from the 3.3v line internally! (neat!)
display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // initialize with the I2C adders 0x3D (for the 128x64)
// init done
// Show image buffer on the display hardware.
// Since the buffer is initialized with an Adafruit splash screen
// internally, this will display the splash screen.
display.display();
delay(2000);
// Clear the buffer.
display.clearDisplay(); //
// draw a single pixel
display.drawPixel(10, 10, WHITE); //
// Show the display buffer on the hardware.
// NOTE: You _must_ call display after making any drawing commands
// to make them visible on the display hardware!
display.display(); //
delay(2000); //
display.clearDisplay(); //
}
void loop() {
unsigned long t1; //
unsigned long t2; //
// Hold the trigger pin high for at least 10 us
digitalWrite(TRIG_PIN, HIGH);
delayMicroseconds(10); //
digitalWrite(TRIG_PIN, LOW); //
// Wait for pulse on echo pin
// while ( digitalRead(ECHO_PIN) == 0 ); //
pulse_width = pulseIn(ECHO_PIN,HIGH); //
// Calculate distance in centimeters and inches. The constants
// are found in the datasheet.
cm = (pulse_width*0.034)/2;// / 58.0; //
inches = (pulse_width*0.0133)/2; // 148.0; //
pingCount++; //
//set average distance and reset it every x pings
if(pingCount>10){
dist=inches; //
pingCount= 1; //
}
else {
dist= dist+inches++; //
avgDist = dist/pingCount; //
}
if(pingCount==10){
printReadings(); //
}
if (avgDist < 10){
// playTone(); //previously had it play tones over a piezo based on distance from the sensor
}
else {
// noTone(piezo); //
}
// Wait at least 60ms before next measurement
delay(60); //
}
void printReadings()
{
// Print out results
if ( pulse_width > MAX_DIST ) {
Serial.println("Out of range"); //
display.setTextSize(1); //
display.setTextColor(WHITE); //
display.setCursor(0,0); //
display.println("Out of range"); //
display.display(); //
}
else if (pulse_width <MIN_DIST) {
display.print(pulse_width); //
Serial.println("Object to close!!") ; //
display.setTextSize(1); //
display.setTextColor(WHITE); //
display.setCursor(0,0); //
display.println("Object to close!!"); //
display.display(); //
}
else {
Serial.print(pingCount); //
Serial.print(" pc \t"); //
Serial.print(avgDist); //
Serial.print(" avgInch \t"); //
Serial.print(cm); //
Serial.print(" cm \t"); //
Serial.print(inches); //
Serial.println(" in"); //
display.setTextSize(1); //
display.setTextColor(WHITE); //
display.setCursor(0,0); //
display.print(pingCount); //
display.print(" pc \t"); //
display.print(avgDist); //
display.print(" avgInch \t"); //
display.print(cm);
display.print(" cm \t"); //
display.print(inches); //
display.println(" in"); //
display.display(); //
}
delay(1000);
display.clearDisplay(); //
}
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define OLED_RESET 4
Adafruit_SSD1306 display(OLED_RESET);
#define XPOS 0
#define YPOS 1
#define DELTAY 2
