admin

admin

 
TPicShow is an image slider VCL that enables you to create amazing splash screens and 176 transitional effects in pure Delphi code.
 
Features:
  1. Image transition can be controlled programmatically
  2. Image can be stretched or centered in the client area of the control
  3. Control can show a background image as centered, stretched, or tiled
  4. Transition process can use a separate thread
  5. New transitional effects can be easily implemented and added.
 
TPicShow's last update is on July 19, 2010 which does not support RAD Studio XE. By creating a package file, you can installing and running TPicShow on RAD Studio XE5 without any problem.
 
Count number of digits in a number(integer). Eg. countDigits(5678) return 4
  1. byte countDigits(int num){
  2. byte count=0;
  3. while(num){
  4. num=num/10;
  5. count++;
  6. }
  7. return count;
  8. }
 
 
Extract a digit from an number(integer). Eg. getDigit(5678,2) return 6
  1. int getDigit(unsigned int number, int digit) {
  2. for (int i=0; i<digit-1; i++) {
  3. number /= 10;
  4. }
  5. return number % 10;
  6. }
 
 
Extract all digits from a number and store them to an array
  1. #define MAX_NUMBER_OF_DIGITS 5
  2. byte array_to_hold_digit[MAX_NUMBER_OF_DIGITS];
  3.  
  4. void setup(void) {
  5. Serial.begin(9600);
  6. extractDigit_Save2Arrary(5678);
  7. Serial.println(array_to_hold_digit[0]);
  8. Serial.println(array_to_hold_digit[1]);
  9. Serial.println(array_to_hold_digit[2]);
  10. Serial.println(array_to_hold_digit[3]);
  11. }
  12.  
  13. void loop(void) {
  14.  
  15. }
  16.  
  17. /*----------------------------------------------------------------------------
  18.  count number of digits in a number(integer)
  19. ----------------------------------------------------------------------------*/
  20. void extractDigit_Save2Arrary(int number){
  21. byte number_of_digit = countDigits(number);
  22. for (byte i=0; i<number_of_digit; i++) {
  23. array_to_hold_digit[i] = getDigit(number,number_of_digit-i); //store each digit to array
  24. }
  25.  
  26. /*
  27.   for (byte i=0; i<number_of_digit; i++) {
  28.   Serial.print(array_to_hold_digit[i]);
  29.   }
  30.   Serial.println();
  31.   */
  32. }
  33.  
  34. /*----------------------------------------------------------------------------
  35.  count number of digits in a number(integer)
  36. ----------------------------------------------------------------------------*/
  37. byte countDigits(int number){
  38. byte count=0;
  39. while(number){
  40. number=number/10;
  41. count++;
  42. }
  43. return count;
  44. }
  45.  
  46. /*----------------------------------------------------------------------------
  47.  extract a digit from an number(integer)
  48. ----------------------------------------------------------------------------*/
  49. byte getDigit(unsigned int number, int digit) {
  50. for (int i=0; i<digit-1; i++) {
  51. number /= 10;
  52. }
  53. return number % 10;
  54. }
 
 
Saturday, 21 December 2013 22:21

Debouncing Multiple Switches

If you want to input a manual switch signal into a digital circuit you'll need to debounce the signal so a single press doesn't appear like multiple presses. 
 
There is a Bounce library for Arduino which is very easy to use. However there is limitations with this Bounce library.
  • You are unlikely to enable the internal pull-up resistor on switch pins, therefore each switch require an external pull-up resistor
  • It is not possible to detect the switch state before main loop (setup). When you press a switch during power on, you will never get the state of the switch.
Tuesday, 17 December 2013 21:51

Arduino function with optional argument(s)

Function Declaration and Function Prototypes: function prototype allowing the function to be used before it is defined.
functionReturnType myFunctionName(optionalArgumentType optionalArgument = defaultValue);
 
Function Implementation

functionReturnType myFunctionName(optionalArgumentType optionalArgument);
{
   // put your code here
}

 
Function calls

myFunctionName(); // Use the default value
myFunctionName(1); // Use specific value

 
Example
  1. int myFunction(int optionalArgument = 1);
  2.  
  3. void setup() {
  4. Serial.begin(9600);
  5. }
  6.  
  7. void loop() {
  8. Serial.println(myFunction()); // Use the default value
  9. Serial.println(myFunction(2)); // Use specific value
  10. }
  11.  
  12. int myFunction(int optionalArgument)
  13. {
  14. return optionalArgument;
  15. }
 
The breadboard.zip hardware configuration archieve is not working on Arduino software version 1.0 and above
 
Here is my boards.txt setup for ATMega328 which is working on version 1.0 and above
Modify the file ...\your_arduino_folder\hardware\arduino\boards.txt by adding these few lines:

##############################################################
atmega328bb.name=ATmega328 Optiboot (8MHz internal clock)
atmega328bb.upload.protocol=arduino
atmega328bb.upload.maximum_size=30720
atmega328bb.upload.speed=57600
atmega328bb.bootloader.low_fuses=0xE2
atmega328bb.bootloader.high_fuses=0xDA
atmega328bb.bootloader.extended_fuses=0x05
atmega328bb.bootloader.path=arduino:optiboot
atmega328bb.bootloader.file=optiboot_atmega328.hex
atmega328bb.bootloader.unlock_bits=0x3F
atmega328bb.bootloader.lock_bits=0x0F
atmega328bb.build.mcu=atmega328p
atmega328bb.build.f_cpu=8000000L
atmega328bb.build.core=arduino
atmega328bb.build.variant=standard

 
And here is the boards.txt setup for ATMega8

##############################################################
atmega8noxtal.name=ATmega8 Optiboot (8MHz internal clock)
atmega8noxtal.upload.protocol=arduino
atmega8noxtal.upload.maximum_size=7168
atmega8noxtal.upload.speed=38400
atmega8noxtal.bootloader.low_fuses=0xe4
atmega8noxtal.bootloader.high_fuses=0xc4
#atmega8noxtal.bootloader.path=atmega8_noxtal
atmega8noxtal.bootloader.path=optiboot
atmega8noxtal.bootloader.file=optiboot_atmega8.hex
atmega8noxtal.bootloader.unlock_bits=0x3F
atmega8noxtal.bootloader.lock_bits=0x0F
atmega8noxtal.build.mcu=atmega8
atmega8noxtal.build.f_cpu=8000000L
atmega8noxtal.build.core=arduino
atmega8noxtal.build.variant=standard

 
Note: Do not modify the boards.txt in your Arduino sketch folder (eg. ...\My Documents\Arduino\hardware\...boardx.txt), it will not work.
 
 

Using an Arduino board to burn the bootloader
If your ATMega8/ATmega328 already configured to use external clock, then wire up the Arduino board & microcontroller as show in figure 1, otherwise (microcontroller configured to use internal clock) you can follow either figure 1 or figure 2.

Fig. 1 Using an Arduino board to burn the bootloader

 

Fig. 2 Using an Arduino board to burn the bootloader

  • Upload the ArduinoISP sketch onto your Arduino board.
  • From Tools>Board menu, select ATmega328 Optiboot (8MHz internal clock) if you want to burn the bootloader on ATMega328 microcontroller
  • From Tools>Board menu, select ATmega8 Optiboot (8MHz internal clock) if you want to burn the bootloader on ATMega8 microcontroller
  • From Tools>Programmer> menu, select Arduino as ISP
  • Select Burn Bootloader from Tools menu to start burning bootloader to microcontroller
Tuesday, 05 November 2013 20:36

Sharp GP2Y0A21红外线测距传感器

Sharp GP2Y0A21是一颗红外线测距传感器,易于使用,价钱廉宜,且低功耗。 规格如下:
  • 距离测量范围:10至80cm(4“到32”)
  • 工作电压:4.5V至5.5V
  • 输出类型:模拟电压
  • 平均功耗:35mA
  • 峰值功耗:约200mA
  • 允许的最大角度:> 40°
  • 更新频率/周期:25 Hz/40毫秒
Sunday, 03 November 2013 17:49

Sharp GP2Y0A21 IR distance sensors

Sharp GP2Y0A21 is an infra-red distance measuring sensor unit,  it is extremely effective, easy to use, very affordable and has low power consumption. specification as follow:

  • Distance measuring range: 10 to 80cm (4" to 32")
  • Operating voltage: 4.5V to 5.5V
  • Output type: Analog voltage
  • Average power consumption : 35 mA
  • Peak power consumption : about 200 mA
  • Output voltage differential over distance range: 1.9V 
  • Maximum allowable Angle : > 40 °
  • The frequency of updates/cycle : 25 Hz/40 ms
Burning sketches to the Arduino board with an AVRISP MKII programmer without using the bootloader. This allows you to use the full program space (flash) of the chip on the Arduino board. So with an ATmega328, you will get 32KB instead of 30KB of space. It also avoids the bootloader delay when you power or reset your board.
Tuesday, 22 October 2013 22:13

Identify which Arduino bootloader do I have

Here’s an Arduino sketch which tries to identify the bootloader and reports it on the serial port
 
The sample output look like this:
[bootCheck.2]
  CRC 2048b @ 0x7800 = CD70
  CRC 512b @ 0x7E00 = FD70
Boot loader: OptiBoot 4.4
 

// Detect which type of boot loader is present, using a fixed built-in table
// 2012-03-06 <This email address is being protected from spambots. You need JavaScript enabled to view it.; http://opensource.org/licenses/mit-license.php

#include <avr/pgmspace.h>
#include <util/crc16.h>

#define VERSION "2"

// list of all known boot loaders with their unique signatures
struct { word crc; const char* desc; } signatures[] = {
0x489C, "Duemilanove",
0xF1A0, "Nanode (Duemilanove mod)",
0xFD70, "OptiBoot 4.4",
0, 0
};

static word CalculateChecksum (word addr, word size) {
word crc = ~0;
prog_uint8_t* p = (prog_uint8_t*) addr;
for (word i = 0; i < size; ++i)
crc = _crc16_update(crc, pgm_read_byte(p++));
Serial.print(" CRC ");
Serial.print(size);
Serial.print("b @ 0x");
Serial.print(addr, HEX);
Serial.print(" = ");
Serial.println(crc, HEX);
return crc;
}

static const char* IdentifyBootLoader (word addr, word size) {
word crc = CalculateChecksum(addr, size);
for (byte i = 0; signatures[i].desc != 0; ++i)
if (signatures[i].crc == crc)
return signatures[i].desc;
return 0;
}

void setup () {
Serial.begin(57600);
Serial.println("\n[bootCheck." VERSION "]");

const char* message = IdentifyBootLoader(0x7800, 2048);
if (message == 0)
message = IdentifyBootLoader(0x7E00, 512);
if (message == 0)
message = "(UNKNOWN)";

Serial.print("Boot loader: ");
Serial.println(message);
}

void loop () {}


Tuesday, 15 October 2013 23:27

Arduino通过74HC595扩展IO

 

74HC595是一个价格廉宜的8位移位寄存器,通过3个数据引脚(STCP, SHCP, DS),可以控制几乎无限量的输出。

DS是一个串行数据输入端,每当时钟输入(SHCP)上升沿到来时DS引脚当前电平值在移位寄存器中会移一位,连续进行8次同样的动作,就可以完成全部(Q0至Q7)移位。最后当STCP(Latch)上升沿到来时,移位寄存器的值将会被锁定在存储器里,并从Q0至Q7引脚输出。

Arduino UNO只有14+6个数字输出,如果需要更多的输出,其中之一的方法就是通过74HC595来取得更多的输出。 

Back to Top