PUT YOUR CURSOR AT MENU BUTTON AND SCROLL UP DOWN
BUTTON
const int buttonPin = 2;
const int ledPin = 13;
int buttonState = 0;
void setup()
{
pinMode(ledPin, OUTPUT);
pinMode(buttonPin, INPUT);
}
void loop()
{
buttonState = digitalRead(buttonPin);
if (buttonState == HIGH)
{
digitalWrite(ledPin, HIGH);
}
else
{
digitalWrite(ledPin, LOW);
}
}
//NOTE:
//Button pin 2
//LED pin 13
const int ledPin = 13;
int buttonState = 0;
void setup()
{
pinMode(ledPin, OUTPUT);
pinMode(buttonPin, INPUT);
}
void loop()
{
buttonState = digitalRead(buttonPin);
if (buttonState == HIGH)
{
digitalWrite(ledPin, HIGH);
}
else
{
digitalWrite(ledPin, LOW);
}
}
//NOTE:
//Button pin 2
//LED pin 13
TEMPERATURE
float temp;
int tempPin = 1;
void setup()
{
analogReference(INTERNAL);
}
void loop()
{
temp = analogRead(tempPin);
Serial.println(temp);
Serial.println("'C.");
delay(400);
}
//NOTE:
//LM35
//Sensor at pin A1
int tempPin = 1;
void setup()
{
analogReference(INTERNAL);
}
void loop()
{
temp = analogRead(tempPin);
Serial.println(temp);
Serial.println("'C.");
delay(400);
}
//NOTE:
//LM35
//Sensor at pin A1
INFRARED RECEIVER
#include "IRremote.h"
int receiver = 11;
IRrecv irrecv(receiver);
decode_results results;
void setup()
{
Serial.begin(9600);
irrecv.enableIRIn();
}
void loop()
{
if (irrecv.decode(&results))
{
Serial.println(results.value, HEX);
translateIR();
irrecv.resume();
}
}
void translateIR()
{
switch(results.value)
{
case 0xFF30CF:
Serial.println(" 1 ");
break;
case 0xFF18E7:
Serial.println(" 2 ");
break;
case 0xFF7A85:
Serial.println(" 3");
break;
case 0xFF10EF:
Serial.println(" 4 ");
break;
case 0xFF38C7:
Serial.println(" 5 ");
break;
case 0xFF5AA5:
Serial.println(" 6 ");
break;
case 0xFF42BD:
Serial.println(" 7 ");
break;
case 0xFF4AB5:
Serial.println(" 8 ");
break;
case 0xFF52AD:
Serial.println(" 9 ");
break;
default:
Serial.println(" other ");
}
delay(500);
}
//NOTE:
//IR SENSOR AT PIN 11
int receiver = 11;
IRrecv irrecv(receiver);
decode_results results;
void setup()
{
Serial.begin(9600);
irrecv.enableIRIn();
}
void loop()
{
if (irrecv.decode(&results))
{
Serial.println(results.value, HEX);
translateIR();
irrecv.resume();
}
}
void translateIR()
{
switch(results.value)
{
case 0xFF30CF:
Serial.println(" 1 ");
break;
case 0xFF18E7:
Serial.println(" 2 ");
break;
case 0xFF7A85:
Serial.println(" 3");
break;
case 0xFF10EF:
Serial.println(" 4 ");
break;
case 0xFF38C7:
Serial.println(" 5 ");
break;
case 0xFF5AA5:
Serial.println(" 6 ");
break;
case 0xFF42BD:
Serial.println(" 7 ");
break;
case 0xFF4AB5:
Serial.println(" 8 ");
break;
case 0xFF52AD:
Serial.println(" 9 ");
break;
default:
Serial.println(" other ");
}
delay(500);
}
//NOTE:
//IR SENSOR AT PIN 11
ULTRASONIC
#include <NewPing.h>
#define TRIGGER_PIN 12
#define ECHO_PIN 11
#define MAX_DISTANCE 200
NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE);
void setup()
{Serial.begin(9600);}
void loop()
{
delay(100);
int uS = sonar.ping();
Serial.println(uS / US_ROUNDTRIP_CM);
Serial.println("cm.");
}
//NOTE:
//TRIGGER PIN 12
//ECHO PIN 11
#define TRIGGER_PIN 12
#define ECHO_PIN 11
#define MAX_DISTANCE 200
NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE);
void setup()
{Serial.begin(9600);}
void loop()
{
delay(100);
int uS = sonar.ping();
Serial.println(uS / US_ROUNDTRIP_CM);
Serial.println("cm.");
}
//NOTE:
//TRIGGER PIN 12
//ECHO PIN 11
LCD Arduino
#include <LiquidCrystal.h>
LiquidCrystal lcd(7, 6, 5, 4, 3, 2);
void setup()
{
lcd.begin(16, 2);
lcd.setCursor(3, 0);
lcd.print("Malaysia Boleh");
}
void loop()
{
lcd.setCursor(8, 1);
lcd.print(millis()/1000);
}
//NOTE:
//LCD RS pin to digital pin 7
//LCD Enable pin to digital pin 6
//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, VSS, V0, K pin to ground
//LCD A pin to 5v
//LCD VDD pin to 3v or 1k-5v
LiquidCrystal lcd(7, 6, 5, 4, 3, 2);
void setup()
{
lcd.begin(16, 2);
lcd.setCursor(3, 0);
lcd.print("Malaysia Boleh");
}
void loop()
{
lcd.setCursor(8, 1);
lcd.print(millis()/1000);
}
//NOTE:
//LCD RS pin to digital pin 7
//LCD Enable pin to digital pin 6
//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, VSS, V0, K pin to ground
//LCD A pin to 5v
//LCD VDD pin to 3v or 1k-5v
ARDUINO BLINK
int led = 13;
void setup()
{
pinMode(led, OUTPUT);
}
void loop() {
digitalWrite(led, HIGH);
delay(1000);
digitalWrite(led, LOW);
delay(1000);
}
void setup()
{
pinMode(led, OUTPUT);
}
void loop() {
digitalWrite(led, HIGH);
delay(1000);
digitalWrite(led, LOW);
delay(1000);
}
RESIZE IMAGE
COMMAND
FOR SIZE 640x480
resize=imresize(im,[640 480])
FOR SIZE 320x240
resize=imresize(im,[320 240])
FOR SIZE 64x48
resize=imresize(im,[64 48])
FOR SIZE 32x32
resize=imresize(im,[32 32])
NOTE
*To resize image we want
*Replace "im" with your image from a file
*Show image resize "imshow(resize)"
FOR SIZE 640x480
resize=imresize(im,[640 480])
FOR SIZE 320x240
resize=imresize(im,[320 240])
FOR SIZE 64x48
resize=imresize(im,[64 48])
FOR SIZE 32x32
resize=imresize(im,[32 32])
NOTE
*To resize image we want
*Replace "im" with your image from a file
*Show image resize "imshow(resize)"
SHOW AND SAVE
SHOW IMAGE
COMMAND
imshow(im)
NOTE
*Display the image
*Replace "im" with your image from a file
SAVE IMAGE
COMMAND
imwrite(im,'D:\test\image name.bmp','bmp')
NOTE
*Replace "im" with your image from a file
*Save part "D:\test\image name.bmp"
*Image format can change with format below
COMMAND
imshow(im)
NOTE
*Display the image
*Replace "im" with your image from a file
SAVE IMAGE
COMMAND
imwrite(im,'D:\test\image name.bmp','bmp')
NOTE
*Replace "im" with your image from a file
*Save part "D:\test\image name.bmp"
*Image format can change with format below
CAMERA SETTING
properties=imaqhwinfo
prop=imaqhwinfo('winvideo')
prop=imaqhwinfo('winvideo',1)
prop.SupportedFormats
videobj=videoinput('winvideo',1,'YUY2_640x480');
im=getsnapshot(videobj)
prop=imaqhwinfo('winvideo')
prop=imaqhwinfo('winvideo',1)
prop.SupportedFormats
videobj=videoinput('winvideo',1,'YUY2_640x480');
im=getsnapshot(videobj)
Subscribe to:
Posts (Atom)











