Hi Folks,
Thanks so much for looking at this. This is the mblock and the ‘c’ it generated, and following that is a paste of the sample program I have run successfully (which was compiled from the Arduino IDE. Apologies for the awful ‘code’ Im sure Im missing something really obvious - just cant see it!
Cheers
Chris
// generated by mBlock5 for
// codes make you happy
#include <Arduino.h>
#include <Wire.h>
#include <SoftwareSerial.h>
float counter = 0;
float latch = 0;
float clock = 0;
float data = 0;
float divi = 0;
float outputbit = 0;
float tval = 0;
float result = 0;
float wait = 0;
float digit = 0;
float value = 0;
void _delay(float seconds) {
long endTime = millis() + seconds * 1000;
while(millis() < endTime) _loop();
}
void setup() {
pinMode(latch,OUTPUT);
pinMode(data,OUTPUT);
pinMode(clock,OUTPUT);
wait = 0.01;
data = 8;
clock = 10;
latch = 9;
digit = 0;
value = 128;
for(int count=0;count<10;count++){
tval = value;
counter = 0;
divi = 128;
digitalWrite(latch,0);
while(!(counter == 8.000000))
{
_loop();
digitalWrite(latch,0);
outputbit = floor(tval / divi);
if(outputbit == 1.000000){
digitalWrite(data,1);
tval = ((tval - divi));
}else{
digitalWrite(data,0);
}
_delay(float(wait));
digitalWrite(clock,1);
_delay(float(wait));
digitalWrite(clock,0);
divi = divi / 2;
counter += 1;
}
_delay(float(wait));
digitalWrite(latch,1);
_delay(1);
}
}
void _loop() {
}
void loop() {
_loop();
}
_sample program which works ok on the same board/prototype setup
//www.elegoo.com
//2016.12.12
// define the LED digit patterns, from 0 - 9
// 1 = LED on, 0 = LED off, in this order:
// 74HC595 pin Q0,Q1,Q2,Q3,Q4,Q5,Q6,Q7
// Mapping to a,b,c,d,e,f,g of Seven-Segment LED
byte seven_seg_digits[10] = { B11111100, // = 0
B01100000, // = 1
B11011010, // = 2
B11110010, // = 3
B01100110, // = 4
B10110110, // = 5
B10111110, // = 6
B11100000, // = 7
B11111110, // = 8
B11100110 // = 9
};
// connect to the ST_CP of 74HC595 (pin 3,latch pin)
int latchPin = 9;
// connect to the SH_CP of 74HC595 (pin 4, clock pin)
int clockPin = 10;
// connect to the DS of 74HC595 (pin 2)
int dataPin = 8;
void setup() {
// Set latchPin, clockPin, dataPin as output
pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(dataPin, OUTPUT);
}
// display a number on the digital segment display
void sevenSegWrite(byte digit) {
// set the latchPin to low potential, before sending data
digitalWrite(latchPin, LOW);
// the original data (bit pattern)
shiftOut(dataPin, clockPin, LSBFIRST, seven_seg_digits[digit]);
// set the latchPin to high potential, after sending data
digitalWrite(latchPin, HIGH);
}
void loop() {
// count from 9 to 0
for (byte digit = 10; digit > 0; --digit) {
delay(100);
sevenSegWrite(digit - 1);
}
// suspend 4 seconds
delay(100);
}