Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save buildcircuit/ec04775dbf23e531ebf7 to your computer and use it in GitHub Desktop.
Save buildcircuit/ec04775dbf23e531ebf7 to your computer and use it in GitHub Desktop.
Android Emulator and CD4094 experiment using Amarino shield
/* Shift Out Data
Decimal to Binary using Android Emulator
*
works with Arduino 1.0 and above
*/
int ledPin=11;
int data = 8;//Connect Pin 8 of Arduino to pin 2 of CD4094 or HEF4794
int strob = 7;//Connect Pin 12 to Pin 1 of CD4094
int clock = 10;//Connect pin 10 of Arduino to pin 3 of CD4094
int oe = 9;//Connect pin 9 of Arduino to pin 15 of CD4094
int count = 0;
int dato = 0;
int value;
String inString = " ";
void setup()
{
Serial.begin(9600);// Your bluetooth adaptor should also have the same baud rate.
// visit http://www.buildcircuit.com/how-to-change-baud-rate-of-bluetooth-modem-bluesmirf-gold-using-arduino-terminal/ for changing the baud rate
pinMode(ledPin, OUTPUT);
pinMode(data, OUTPUT);
pinMode(clock, OUTPUT);
pinMode(strob, OUTPUT);
pinMode(oe, OUTPUT);
Serial.println("Enter digits");
}
void PulseClock(void) {
digitalWrite(clock, LOW);
delayMicroseconds(20);
digitalWrite(clock, HIGH);
delayMicroseconds(50);
digitalWrite(clock, LOW);
}
void Dato(void) {
for (count = 0; count < 8; count++) {
digitalWrite(data, dato & 01);
dato>>=1;
if (count == 7){
digitalWrite(oe, LOW);
digitalWrite(strob, HIGH);
}
PulseClock();
digitalWrite(oe, HIGH);
inString = " ";
}
delayMicroseconds(20);
digitalWrite(strob, LOW);
delay(1000);
}
void loop()
{
while (Serial.available() > 0) {
int inChar = Serial.read();
if (isDigit(inChar)) {
inString += (char)inChar;
}
if (inChar == '?') {
Serial.print("Value:");
Serial.println(inString.toInt());
Serial.println("******************");
value = inString.toInt();
dato= value;
if (dato == 0)
{
dato = 0;
Dato();
digitalWrite(ledPin, HIGH);
PulseClock();
digitalWrite(oe, HIGH);
}
else if (dato >255 ) // for all values above 255, dato= 255; all LEDs glow.
{
dato = 255;
Dato();
PulseClock();
digitalWrite(ledPin, LOW);
digitalWrite(oe, HIGH);
Serial.println("******************");
Serial.print("Enter value 0-255");
Serial.println(" ");
Serial.println("******************");
}
else
{
Dato();
digitalWrite(ledPin, LOW);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment