oh blog

Icon

i rant cherish and archive my memories here

AZ1086 3.3V regulator

1: Ground
2: Output
3: Input

Filed under: pcomp

[final] Arduino code for TV/111806

/*NOTE:

similar as pedometer. works with manual-type-ins. not sure with ‘\r’ after Serial.print*/

/* TV power control with BT communication
jane oh
11.18.06
*/
#define tvPin 2
#define powerPin 3
#define ledPin 13
#define inPin 12
#define break 50

int inByte = -1;
char inString[4];
int stringPos = 0;
int counter = 0;
long power = 0;
int button = 0;
int currentState = 0;
int preState = 0;

void setup()
{
pinMode(inPin, INPUT);
pinMode(powerPin, OUTPUT);
pinMode(ledPin, OUTPUT);
pinMode(tvPin, OUTPUT);     // sets the digital pin as output
Serial.begin(9600);

blink(3);   //blinkie
}

void loop(){
//send data only when you receive data
if (Serial.available() > 0) {
digitalWrite(ledPin, HIGH);
inByte = Serial.read();

//when receive ‘P’ send ‘T’ as response
if (inByte == ‘P’){
//blink(2);
Serial.print(‘T’); //”T” needed?!?!
delay(break);
delay(break);
//ask for counter value
Serial.print(‘C’);
delay(break);
}
//when receive counter value, store it and send ‘G’ as good
if ((inByte >= ‘0′) && (inByte <= ‘9′)){
//blink(2);
inString[stringPos] = inByte;
stringPos++;
//give ‘G’ as in good transfer of data
Serial.print(‘G’);
delay(break);
}
if (inByte == ‘S’){
blink(2);
counter = atoi(inString);
//Serial.print(counter);
power = counter * 1000;
//Serial.print(power);
// put zeroes in the array
for (int c = 0; c < stringPos; c++) {
inString[c] = 0;
}
// reset the string pointer:
stringPos = 0;
}
}

//turn on TV when press the button
button = digitalRead(inPin);
if (button == HIGH){
currentState = 1;
}
else {
currentState = 0;
}
if (currentState != preState){
if (currentState == 1){
powerControl();
}
}
preState = currentState;
}

//turn on TV for the amount of counter time
void powerControl(){
for (long i=0; i <= power; i++){
digitalWrite(tvPin, HIGH);
digitalWrite(powerPin, HIGH);
//Serial.print(i);
if (i == power){
digitalWrite(tvPin, LOW);
digitalWrite(powerPin, LOW);
}
}
counter = 0;
power = 0;
}

// Blink an LED:
void blink(int howManyTimes) {
for (int i=0; i< howManyTimes; i++) {
digitalWrite(ledPin, HIGH);
delay(200);
digitalWrite(ledPin, LOW);
delay(200);
}
}

Filed under: Networked Objects, pcomp

[final] Arduino code for Pedometer/111806

/*NOTE:

it kinda works logically with serial-USB connection and with mannually-typed-in commands. but had some troubles with BT communication- virtual serial port error – and Signal Strength detection – timing, swtiching between dataMode and commandMode with \r, uncertainty with Strength indicator value and all.. -  */

/* pedometer counter with BT communication
jane oh
11.18.06
**********reminder**************
miniarduino: atmega168
serial baudrate: 9600
********************************
*/
#define ledPin 13  // choose the pin for the LED
#define statPin 12
#define inPin 9    // choose the input pin (for a pushbutton)
#define break 500   // variable for the break after serial send

int val = 0;     // variable for reading the pin status
int stat = 0;    // variable for BT status
int counter = 0;
int currentState = 0;
int preState = 0;

int inByte = -1;
boolean far = false;

void setup() {
pinMode(ledPin, OUTPUT);  // declare LED as output
pinMode(statPin, OUTPUT);
pinMode(inPin, INPUT);    // declare pushbutton as input
Serial.begin(9600);

blink(3);  //blinkie

digitalWrite(inPin, LOW);
}

void loop(){
inByte = Serial.read();
if (inByte == ‘T’){ //need to type ‘T’ not T. weird..
stat = 1;
}

if (far){
stat = 0;
}

//when connected, do BT communication
if (stat == 1){
digitalWrite(statPin, HIGH);
BTtalk();
}
//when disconnected, send signal and start counting
if (stat == 0) {
digitalWrite(statPin, LOW);
//Serial.print(‘P’);
//delay(break);
stepCount();
}
}

void stepCount(){
val = digitalRead(inPin);  // read input value
if (val == HIGH) {         // check if the input is HIGH
digitalWrite(ledPin, HIGH);  // turn LED ON
currentState = 1;
}
else {
digitalWrite(ledPin, LOW);  // turn LED off
currentState = 0;
}

if ((currentState != preState) && (stat == 0)){
if (currentState == 1){
counter = counter + 1;
//Serial.print(counter, DEC);
Serial.print(‘P’);
delay(400); //500 little lagging
}
}
preState = currentState;
}

void BTtalk(){
//when connected to TV, send counter value
if (inByte == ‘C’){
Serial.print(counter, DEC);
delay(break);
//blink(2);
Serial.print(‘S’);
}

//when sent counter value, set the value to 0
if (inByte == ‘G’){
counter = 0;
//blink(2);
}
//detect distance
checkSSI();
}

//get Signal Strength info and detect distance
void checkSSI(){
Serial.print(“+++”); //go into commandMode
// wait for the radio to respond with “OK\r”
char thisByte = 0;
while (thisByte != ‘\r’) {
if (Serial.available() > 0) {
thisByte = Serial.read();
}
}
Serial.print(“ATRSSI\r”); //get the signal strength indicator
if (inByte <= ‘-20′){
far = true;
}
else {
far = false;
}
Serial.print(“ATMD\r”); //go back to datamode
}

// Blink an LED:
void blink(int howManyTimes) {
for (int i=0; i< howManyTimes; i++) {
digitalWrite(statPin, HIGH);
delay(200);
digitalWrite(statPin, LOW);
delay(200);
}
}

Filed under: Networked Objects, pcomp

Spoiled Gumball Machine code

spoiledgumballmachine.com

documentation

http://spoiledgumball.blogspot.com/ 

‘****************************************************************
‘* Name : gumball121205.BAS *
‘* Author : gumball group *
‘* Notice : Copyright (c) 2004 [select VIEW...EDITOR OPTIONS] *
‘* : All Rights Reserved *
‘* Date : 12/12/2005 *
‘* Version : 1.0 *
‘* Notes : *
‘* : *
‘****************************************************************
DEFINE OSC 4
start:
INCLUDE “modedefs.bas”
‘ Define ADCIN parameters
‘ Set number of bits in result
DEFINE ADC_BITS 10
‘ Set clock source (3=rc)
DEFINE ADC_CLOCK 3
‘ Set sampling time in microseconds
DEFINE ADC_SAMPLEUS 10
‘ Set PORTA to all input
TRISA = %11111111
‘ Set up ADCON1 analog and right justify the result
adcon1 = %10000010

pause 500

‘define inputs and outputs
‘test
output PORTD.0
‘LEDs for testing
OUTPUT PORTD.1
‘play
OUTPUT PORTD.2
’stop
OUTPUT PORTD.3
‘FF
OUTPUT PORTC.4
‘RW
OUTPUT PORTC.5
’solenoids
OUTPUT PORTC.1
OUTPUT PORTC.2
OUTPUT PORTC.3
‘LEDs
OUTPUT PORTB.0

‘PIEZO from other board
INPUT PORTB.6
‘beginning switch
Input PORTB.7

’set all the input ports low
LOW PORTD.0
LOW PORTD.1
LOW PORTD.2
LOW PORTD.3
LOW PORTC.4
LOW PORTC.5
LOW PORTB.5
LOW PORTB.6
LOW PORTB.7
LOW PORTC.1
LOW PORTC.2
LOW PORTC.3
LOW PORTB.0

pause 500

‘define adc vars
adcVar1 VAR WORD  ‘PIEZO(move)
adcVar2 VAR WORD  ‘MIC(sound)
adcVar3 VAR WORD  ‘FSR(touch)

’set vars
theStage var byte
trackPlayed VAR BYTE
jumpLevel var WORD
whisperLevel var WORD
touchLevel var WORD
startup var byte
counter VAR WORD
countEval var byte
petCounter VAR BYTE

’set your acceptable params here
jumpLevel = 500
whisperLevel = 300
touchLevel  = 600
counter = 0
petCounter = 0

’set your booleans here
theStage = 0
trackPlayed =0
startup = 1
countEval =0

‘test out the start with LED blinking
HIGH PORTD.1
pause 200
LOW PORTD.1
pAUSE 200
HIGH PORTD.1
pause 200
LOW PORTD.1
pAUSE 200
HIGH PORTD.1
pause 200
LOW PORTD.1
pAUSE 200

”test out the start with Solenoid moving
‘HIGH PORTB.5
‘pause 500
‘LOW PORTB.5
‘pAUSE 500
‘HIGH PORTB.5
‘pause 500
‘LOW PORTB.5
‘pAUSE 500

‘prep the cd
IF startup = 1 Then
’start the CD player
HIGH PORTD.2
pause 500
low PORTD.2
pause 7000 ‘heating up time
‘pause the CD player
HIGH PORTD.2
pause 500
low PORTD.2
startup = 0
EndIf

main:
‘initiating cycle
if theStage = 0 then
‘if the user has turned the handle start the program
if PORTB.7 = 1 then
‘play the first track and pause cd player(#1)
High PORTD.2
PAUSE 500
LOW PORTD.2
PAUSE 250
Pause 6500 ‘time of intro song
‘light up the LEDs
HIGH PORTB.0
PAUSE 7000
LOW PORTB.0

‘pause CD player
High PORTD.2
PAUSE 500
LOW PORTD.2
PAUSE 250

theStage = 1
endIF
endIF

‘jump
if theStage = 1 then
‘make sure serial communicator has Baudrate of 9600!
‘trigger this with a boolean
if trackPlayed = 0 then
‘play the first track and pause cd player(#2)
High PORTD.2
PAUSE 500
LOW PORTD.2
PAUSE 250
Pause 5500 ‘time of task one track
‘light up the LEDs
HIGH PORTB.0
PAUSE 6000
LOW PORTB.0

‘pause CD player
High PORTD.2
PAUSE 500
LOW PORTD.2
PAUSE 250

trackPlayed = 1
endIF

‘we need to give some time test ppl’s jumping;
‘what if we have blank sound after the voice in a track
‘to give time to test instead of pausing??

‘make sure serial communicator has Baudrate of 9600!
test1
ADCIN 1, adcVar1
serout2 portc.6, 16468, [DEC adcVar1,10,13]

counter = counter + 1
‘light up the LEDs

IF adcVar1 >= jumplevel then
‘forward to the proper track
HIGH PORTC.4
PAUSE 500
LOW PORTC.4
PAUSE 500
‘play the proper track(#4)
High PORTD.2
PAUSE 500
LOW PORTD.2
PAUSE 250
pause 2500   ‘time of third track
‘light up the LEDs
HIGH PORTB.0
PAUSE 3000
LOW PORTB.0

‘Pause CD player
High PORTD.2
PAUSE 500
LOW PORTD.2
PAUSE 250
‘open first solenoid
HIGH PORTC.1
PAUSE 2000
LOW PORTC.1
PAUSE 250

theStage = 2
trackPlayed = 0
countEval=1
ENDIF
‘not enough
IF counter = 1000 and countEval = 0 THEN
‘play the proper track(#3)
High PORTD.2
PAUSE 500
LOW PORTD.2
PAUSE 250
pause 5000   ‘time of third track
‘light up the LEDs
HIGH PORTB.0
PAUSE 5500
LOW PORTB.0

‘Pause CD player
High PORTD.2
PAUSE 500
LOW PORTD.2
PAUSE 250
‘rewind the track
HIGH PORTC.5
PAUSE 500
LOW PORTC.5
PAUSE 500
counter = 0
GOTO test1
endIF
endIF

‘touch
if theStage = 2 then
‘trigger this with a boolean
if trackPlayed = 0 then
countEval = 0
counter = 0
‘play the second challenge track and pause cd player(#5)
High PORTD.2
PAUSE 500
LOW PORTD.2
PAUSE 250
Pause 6500 ‘time of fourth track
‘light up the LEDs
HIGH PORTB.0
PAUSE 7000
LOW PORTB.0

‘pause CD player
High PORTD.2
PAUSE 500
LOW PORTD.2
PAUSE 250
trackPlayed = 1
endIF

test2
ADCIN 2, adcVar2
serout2 portc.6, 16468, [ DEC adcVar2,10,13]

‘  petCounter = petCounter + 1
counter = counter + 1

if adcVar2 >= touchLevel then
petCounter = petCounter + 1
if  petCounter = 200 then
‘forward to the proper track
HIGH PORTC.4
PAUSE 500
LOW PORTC.4
PAUSE 500
‘play the proper track(#7)
High PORTD.2
PAUSE 500
LOW PORTD.2
PAUSE 250
pause 4500  ‘time of the track
‘light up the LEDs
HIGH PORTB.0
PAUSE 5000
LOW PORTB.0

‘Pause CD player
High PORTD.2
PAUSE 500
LOW PORTD.2
PAUSE 250
‘open second solenoid
HIGH PORTC.2
PAUSE 2000
LOW PORTC.2
PAUSE 250

theStage = 3
trackPlayed = 0
countEval = 1
endif
endIF
‘not enough
IF counter = 1000 and countEval = 0 THEN
‘play the proper track(#6)
High PORTD.2
PAUSE 500
LOW PORTD.2
PAUSE 250
pause 8000   ‘time of the track
‘light up the LEDs
HIGH PORTB.0
PAUSE 8500
LOW PORTB.0

‘Pause CD player
High PORTD.2
PAUSE 250
LOW PORTD.2
PAUSE 250
‘rewind the track
HIGH PORTC.5
PAUSE 500
LOW PORTC.5
PAUSE 500

counter=0
GOTO test2
endIF
endIF

‘whisper
if theStage = 3 then
‘trigger this with a boolean
if trackPlayed = 0 then
countEval = 0
counter = 0
‘play the third challenge track and pause cd player(#8)
High PORTD.2
PAUSE 500
LOW PORTD.2
PAUSE 250
Pause 8500 ‘time of the track
‘light up the LEDs
HIGH PORTB.0
PAUSE 9000
LOW PORTB.0

‘pause CD player
High PORTD.2
PAUSE 500
LOW PORTD.2
PAUSE 250
trackPlayed = 1
endIF

test3
ADCIN 3, adcVar3
serout2 portc.6, 16468, [ DEC adcVar3,10,13]

counter = counter + 1

if adcVar3 >= whisperLevel then
‘forward to the proper track
HIGH PORTC.4
PAUSE 500
LOW PORTC.4
PAUSE 500
‘play the proper track(#10)
High PORTD.2
PAUSE 500
LOW PORTD.2
PAUSE 250
pause 4500 ‘time of the track
‘light up the LEDs
HIGH PORTB.0
PAUSE 5000
LOW PORTB.0

‘Pause CD player
High PORTD.2
PAUSE 500
LOW PORTD.2
PAUSE 250

theStage = 4
trackPlayed = 0
countEval = 1
endIF
‘not enough
IF counter = 1000 and countEval = 0 THEN
‘play the proper track(#9)
High PORTD.2
PAUSE 500
LOW PORTD.2
PAUSE 250
pause 4500   ‘time of the track
‘light up the LEDs
HIGH PORTB.0
PAUSE 5000
LOW PORTB.0

‘Pause CD player
High PORTD.2
PAUSE 500
LOW PORTD.2
PAUSE 250
‘rewind the track
HIGH PORTC.5
PAUSE 500
LOW PORTC.5
PAUSE 500
counter=0
GOTO test3

endIF
endif

‘celebration of achievement
if theStage = 4 then
‘trigger this with a boolean
if trackPlayed = 0 then
‘play the congratulations and reset cd player(#11)
High PORTD.2
PAUSE 500
LOW PORTD.2
PAUSE 250
Pause 8000  ‘time of final:good-bye track
‘light up the LEDs
HIGH PORTB.0
PAUSE 8500
LOW PORTB.0

‘pause CD player
High PORTD.2
PAUSE 500
LOW PORTD.2
PAUSE 250
‘       ‘open third solenoid
HIGH PORTC.3
PAUSE 2000
LOW PORTC.3
PAUSE 250

trackPlayed = 1
endIF
theStage = 5
trackPlayed = 0
endif

IF theStage = 5 THEN
‘reset the CD player (forward to the first track and wait)
HIGH PORTC.4
PAUSE 500
LOW PORTC.4
PAUSE 500
theStage = 0
LOW PORTB.7

ENDIF

goto main

Filed under: pcomp

[Recurring Art] Walking Potato

Digilog: Digital technology + Analog sentiment

subversive art?

.

Marcel Duchamp:

google images

Wim Delvoye:

http://www.cloaca.be/machines.htm

google images

Filed under: Networked Objects, pcomp

source

Filed under: pcomp

TV control with transistor TIP120

 got a tv (COBY B/W model from JnR) and got its power controlled with TIP120 transistor.

tv

next step will be set up Bluetooth so that pedometer and TV can communicate to each other.

——————-

<code>

——————–

/* TV simple power control
*/

int tvPin = 2;
int ledPin = 13;

void setup()
{
pinMode(ledPin, OUTPUT);
pinMode(tvPin, OUTPUT); // sets the digital pin as output

digitalWrite(ledPin, HIGH); // sets the LED on
delay(200); // waits for a second
digitalWrite(ledPin, LOW); // sets the LED off
delay(200); // waits for a second
digitalWrite(ledPin, HIGH); // sets the LED on
delay(200); // waits for a second
digitalWrite(ledPin, LOW); // sets the LED off
delay(200); // waits for a second
digitalWrite(ledPin, HIGH); // sets the LED on
delay(200); // waits for a second
digitalWrite(ledPin, LOW); // sets the LED off
delay(200); // waits for a second
}

void loop()
{
digitalWrite(tvPin, HIGH);
digitalWrite(ledPin, HIGH); // sets the LED on
//delay(5000); // waits for a second
//digitalWrite(tvPin, LOW);
//digitalWrite(ledPin, LOW); // sets the LED off
//delay(5000); // waits for a second
}

Filed under: Networked Objects, pcomp

Pedometer with Mini Arduino

Tested a hacked pedometer with a mini arduino.

Two reminders:

set the chip to ATmega168 when program.

and set serial boudrate to 19200 for the convenience of Bluetooth?!

pedometer with mini arduino

<< click the image to enlarge >>

code

—————————

/* pedometer simple counter
jane oh
10.30.06
**********reminder**************
miniarduino: atmega168
serial baudrate: 19200
********************************
*/

int ledPin = 13; // choose the pin for the LED
int inPin = 9; // choose the input pin (for a pushbutton)
int val = 0; // variable for reading the pin status
int counter = 0;
int currentState = 0;
int preState = 0;
void setup() {
pinMode(ledPin, OUTPUT); // declare LED as output
pinMode(inPin, INPUT); // declare pushbutton as input
Serial.begin(19200);

digitalWrite(ledPin, HIGH); //blinkie
delay(200);
digitalWrite(ledPin, LOW);
delay(200);
digitalWrite(ledPin, HIGH);
delay(200);
digitalWrite(ledPin, LOW);
delay(200);

digitalWrite(inPin, LOW);
}

void loop(){
val = digitalRead(inPin); // read input value
if (val == HIGH) { // check if the input is HIGH (button pushed)
digitalWrite(ledPin, HIGH); // turn LED ON
currentState = 1;
}
else {
digitalWrite(ledPin, LOW); // turn LED off
currentState = 0;
}
if (currentState != preState){
if (currentState == 1){
counter = counter + 1;
Serial.print(counter, DEC);;
delay(500);
}
}
preState = currentState;
}

Filed under: Networked Objects, pcomp

Mini Arduino!

finally got the mini arduinos, tested with a blinking LED!

mini

so small!

mini arduino with blinkie

simple setup with diagrams found on arduino site.
http://www.arduino.cc/en/Main/ArduinoBoardMini

http://www.arduino.cc/en/Main/ArduinoMiniUSB

nicely mounts on bread board.

when program,

remember the chip is atmega168!! (different from the regular arduino with atmega8)

excited to build a perf board for it :)

Filed under: pcomp

pedometer take2

pedometer take2

with tom’s advice, decided to connect one end of a switch to 5V of arduino board and the other end to the input pin(with 10k ohm pull down resistor).

since the circuitry on pedometer was not exactly a switch but a connection between ground to power to give a reading to a display, i kept the circuitry for the sake of keeping the display, then needed to put a seperate wire as an end of switch. (the one that connects to the input pin)
for the arduino code, added a simple counter that counts the steps with pedometer. had to figure out to limit/slow down the reading as it counted multiple times with one click of a switch. Therefore, put ’status’ variables, and also ‘delay’ to put some breaks between the readings.

<arduino code>

—————————-

/* pedometer with simple counter
jane oh
10.30.06
*/

int ledPin = 3; // choose the pin for the LED
int inPin = 2; // choose the input pin (for a pushbutton)
int val = 0; // variable for reading the pin status
int counter = 0;
int currentState = 0;
int preState = 0;
void setup() {
pinMode(ledPin, OUTPUT); // declare LED as output
pinMode(inPin, INPUT); // declare pushbutton as input
Serial.begin(9600);

digitalWrite(ledPin, HIGH); //blinkie
delay(200);
digitalWrite(ledPin, LOW);
delay(200);
digitalWrite(ledPin, HIGH);
delay(200);
digitalWrite(ledPin, LOW);
delay(200);

digitalWrite(inPin, LOW);
}

void loop(){
val = digitalRead(inPin); // read input value
if (val == HIGH) { // check if the input is HIGH (button pushed)
digitalWrite(ledPin, HIGH); // turn LED ON
currentState = 1;
}
else {
digitalWrite(ledPin, LOW); // turn LED off
currentState = 0;
}
if (currentState != preState){
if (currentState == 1){
counter = counter + 1;
Serial.print(counter, DEC);;
delay(500);
}
}
preState = currentState;
}
———————————-

Filed under: Networked Objects, pcomp

Twitter updates

del.icio.us